#24279: ORing with an empty Q() produces inconsistent results
-------------------------------------+-------------------------------------
Reporter: ris | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: Q empty in or | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by akaariai):
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0
Comment:
ORin with an empty Q() is something we support. A common pattern is to do
something like this:
{{{
condition = Q()
if foo:
condition = condition | Q(foo=True)
if bar:
condition = condition | Q(bar=True)
qs.filter(condition)
}}}
The empty Q() should not have any effect at all, whether ORed or ANDed
into the query.
I confirmed the issue with a test available in
https://github.com/akaariai/django/tree/ticket_24279.
As it happens, work done in https://github.com/django/django/pull/3779
fixes this issue (it changes the way empty Q() nodes are handled). It
should be committed to master any minute now. I'm not sure if we need to
fix this in 1.8 or 1.7. This isn't a serious bug (as in, things have
worked like this for a long time, and users have survived it). This will
also subtly change results of some queries, so I'm not too enthusiastic to
backpatch this to released versions.
--
Ticket URL: <https://code.djangoproject.com/ticket/24279#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/061.2979434d72d727a9678a64fc0310bbc7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.