Opened 11 years ago

Closed 11 years ago

#3463 closed (fixed)

EmptyQuerySet's iterator() method does not return a generator

Reported by: Gary Wilson <gary.wilson@…> Owned by: Adrian Holovaty
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


>>> User.objects.all().iterator()
<generator object at 0xb76a714c>

>>> User.objects.none().iterator()
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File "./django/db/models/", line 596, in iterator
    raise StopIteration

Attachments (1)

iterator.diff (3.3 KB) - added by Gary Wilson <gary.wilson@…> 11 years ago.

Download all attachments as: .zip

Change History (4)

Changed 11 years ago by Gary Wilson <gary.wilson@…>

Attachment: iterator.diff added

comment:1 Changed 11 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: UnreviewedAccepted

Patch comments:

  • Added test for none().iterator().
  • Moved the cursor() calls after the _get_sql_clause() to avoid unnecessary grabbing of a cursor.
  • EmptyQuerySet
    • Added _get_sql_clause that always raises EmptyResultSet.
    • Removed iterator method so that the parent method gets used instead.

comment:2 Changed 11 years ago by Gary Wilson <gary.wilson@…>

Just noting here that it was [4394] that broke the QuerySet.iterator() interface.

comment:3 Changed 11 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [4475]) Fixed #3463 -- EmptyQuerySet's iterator() now returns a generator. Thanks, Gary Wilson

Note: See TracTickets for help on using tickets.
Back to Top