Re: [Django] #33963: Combining Q objects with empty querysets crashes. (was: Combining Q objects)

4 views
Skip to first unread message

Django

unread,
Aug 29, 2022, 6:09:08 AM8/29/22
to django-...@googlegroups.com
#33963: Combining Q objects with empty querysets crashes.
-------------------------------------+-------------------------------------
Reporter: Bogumil Schube | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

Thanks for the report. As far as I'm aware combining querysets (empty or
not) with `Q()` objects have never been officially supported, documented,
or tests. This worked for empty querysets in Django 4.0, but accidentally
and only due to the order of `EmptyQuerySet` guards. You should use `Q()`
as the starting point for building dynamically `Q` objects, e.g.:
{{{#!python
out = Q()
for a, b in [(1,1),(2,2),(3,3)]:
out |= Q(a=a, b=b)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33963#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages