Opened 18 years ago

Closed 18 years ago

#3283 closed enhancement (fixed)

[patch] creating an empty queryset

Reported by: medhat Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: dev
Severity: normal Keywords: empty queryset
Cc: gary.wilson@… 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

This patch will allow returning an empty queryset from the manager. This way, if in a situation you know that the result of the queryset will be empty you can return the empty queryset instead of using something like 'where 1=0' which will still hit the database.

You can check this thread for a brief discussion about this Creating an empty queryset

Attachments (4)

empty_queryset.patch (1.8 KB ) - added by medhat 18 years ago.
empty_in_clause.patch (3.2 KB ) - added by medhat 18 years ago.
another solution for the empty in-clause using empty querysets
empty_queryset_2.patch (7.1 KB ) - added by medhat 18 years ago.
this should replace the two previous patches, it contains both patches, documentation, and tests.
empty_queryset_3.patch (7.9 KB ) - added by medhat 18 years ago.
Yet another version of the patch that fixes a problem with QNot (with tests)

Download all attachments as: .zip

Change History (10)

by medhat, 18 years ago

Attachment: empty_queryset.patch added

by medhat, 18 years ago

Attachment: empty_in_clause.patch added

another solution for the empty in-clause using empty querysets

comment:1 by medhat, 18 years ago

I have also added another fix for the empty in-clause #2473 using the empty queryset. This fix will not hit the database at all.

comment:2 by medhat, 18 years ago

well, I just realized that my empty-in-clause patch is not dependent on the empty-queryset patch! I guess I need to get some sleep :-)

by medhat, 18 years ago

Attachment: empty_queryset_2.patch added

this should replace the two previous patches, it contains both patches, documentation, and tests.

by medhat, 18 years ago

Attachment: empty_queryset_3.patch added

Yet another version of the patch that fixes a problem with QNot (with tests)

comment:3 by Chris Beaven, 18 years ago

Triage Stage: UnreviewedReady for checkin

Stellar patch.

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

Cc: gary.wilson@… added

Yes, very nice.

comment:5 by Adrian Holovaty, 18 years ago

What a nice patch. Only thing missing is a "**New in Django development version**" note in the documentation, as per our style, but I'll take care of that.

comment:6 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(In [4394]) Fixed #3283 -- Added support for empty QuerySets via none() method. Thanks for the patch, medhat

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