Opened 18 years ago

Closed 18 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: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

>>> 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/query.py", line 596, in iterator
    raise StopIteration
StopIteration

Attachments (1)

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

Download all attachments as: .zip

Change History (4)

by Gary Wilson <gary.wilson@…>, 18 years ago

Attachment: iterator.diff added

comment:1 by Gary Wilson <gary.wilson@…>, 18 years ago

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

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

comment:3 by Adrian Holovaty, 18 years ago

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