Opened 16 years ago

Closed 15 years ago

Last modified 15 years ago

#10291 closed (fixed)

Correction to QuerySet.iterator() documentation

Reported by: Erin Kelly Owned by: nobody
Component: Documentation Version: dev
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

A revision to the documentation for the QuerySet.iterator() method that better reflects how it behaves differently from normal evaluation.

Attachments (1)

10291.diff (1.3 KB ) - added by Erin Kelly 16 years ago.

Download all attachments as: .zip

Change History (9)

by Erin Kelly, 16 years ago

Attachment: 10291.diff added

comment:1 by Alex Gaynor, 16 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Tim Graham, 15 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

looks like a nice clarification to me

comment:3 by Adrian Holovaty, 15 years ago

Resolution: invalid
Status: newclosed

I'm not sure this documentation change is correct/appropriate. The point of iterator() is to do the query in chunks (as explained in the current document), not to avoid caching (as explained in the patch).

comment:4 by Erin Kelly, 15 years ago

Resolution: invalid
Status: closedreopened

Reopening because I think Adrian's determination is incorrect. If I'm missing something, let me know and I'll drop it.

It's true that iterator() fetches the query result in chunks, but normal evaluation using __iter__() also fetches the query result in chunks. Also, any function applied to the result of __iter__() that causes everything to be fetched will do the same when applied to the result of iterator().

In fact, __iter__() invokes iterator() behind the scenes to do the heavy lifting. The only thing it does differently is that it makes use of and fills the QuerySet's _result_cache over the course of iteration. So if iterator() is merely meant to fetch the query result in chunks, why is it even included in the public API when __iter__() already accomplishes this?

comment:5 by Luke Plant, 15 years ago

Looking at the current code, I'm with ikelly on this one, I happened to be looking at this just now. The only thing that changes if you switch to iterator() is that your results will not be cached.

comment:6 by Luke Plant, 15 years ago

Resolution: fixed
Status: reopenedclosed

(In [12229]) Created a 'DB optimization' topic, with cross-refs to relevant sections.

Also fixed #10291, which was related, and cleaned up some inconsistent doc labels.

comment:7 by Luke Plant, 15 years ago

(In [12230]) [1.1.X] Created a 'DB optimization' topic, with cross-refs to relevant sections.

Also fixed #10291, which was related, and cleaned up some inconsistent doc labels.

Backport of r12229 from trunk

comment:8 by Luke Plant, 15 years ago

Oops, meant to says "thanks ikelly" in that commit message, seeing as I used your patch wholesale. Cheers.

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