Code

Opened 2 years ago

Closed 2 years ago

#17523 closed Bug (duplicate)

Slicing: EmptyQuerySet behaves differently from QuerySet

Reported by: rluedeman Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I noticed a slight (but annoying) difference between slicing an EmptyQuerySet and slicing a standard QuerySet. It seems like slicing an EmptyQuerySet should return an EmptyQuerySet, rather than returning a list.

Example:

>> from django.contrib.auth.models import User
>>
>> type(User.objects.all())
<class 'django.db.models.query.QuerySet'>
>> type(User.objects.all()[:0])
<class 'django.db.models.query.QuerySet'>
>> type(User.objects.all()[:10])
<class 'django.db.models.query.QuerySet'>
>>
>> type(User.objects.none())
<class 'django.db.models.query.EmptyQuerySet'>
>> type(User.objects.none()[:0])
<type 'list'>
>> type(User.objects.none()[:10])
<type 'list'>

Attachments (0)

Change History (2)

comment:1 Changed 2 years ago by rluedeman

  • Component changed from Uncategorized to Database layer (models, ORM)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Type changed from Uncategorized to Bug

comment:2 Changed 2 years ago by rluedeman

  • Resolution set to duplicate
  • Status changed from new to closed

nevermind. just discovered this is a dupe of #10139

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.