Opened 10 years ago

Closed 10 years ago

#3283 closed enhancement (fixed)

[patch] creating an empty queryset

Reported by: medhat Owned by: adrian
Component: Database layer (models, ORM) Version: master
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: UI/UX:

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 10 years ago.
empty_in_clause.patch (3.2 KB) - added by medhat 10 years ago.
another solution for the empty in-clause using empty querysets
empty_queryset_2.patch (7.1 KB) - added by medhat 10 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 10 years ago.
Yet another version of the patch that fixes a problem with QNot (with tests)

Download all attachments as: .zip

Change History (10)

Changed 10 years ago by medhat

Changed 10 years ago by medhat

another solution for the empty in-clause using empty querysets

comment:1 Changed 10 years ago by medhat

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 Changed 10 years ago by medhat

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 :-)

Changed 10 years ago by medhat

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

Changed 10 years ago by medhat

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

comment:3 Changed 10 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Ready for checkin

Stellar patch.

comment:4 Changed 10 years ago by Gary Wilson <gary.wilson@…>

  • Cc gary.wilson@… added

Yes, very nice.

comment:5 Changed 10 years ago by adrian

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 Changed 10 years ago by adrian

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

(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