Opened 9 years ago

Closed 9 years ago

#3463 closed (fixed)

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

Reported by: Gary Wilson <gary.wilson@…> Owned by: adrian
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@…> 9 years ago.

Download all attachments as: .zip

Change History (4)

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

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 9 years ago by Gary Wilson <gary.wilson@…>

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

comment:3 Changed 9 years ago by adrian

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

(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