#17600: Error in encapsulates filters (Q)
-------------------------------------+-------------------------------------
Reporter: pmartin | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.3
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Comment (by akaariai):
Hmmh, seems like my interpretation of the `.exclude(~Q(items__status=1))`
was incorrect. It seems this should behave similarly to
`qs.exclude(items__in=Item.objects.filter(~Q(status=1)))`. That is, remove
every Order having at least one item with different status than 1. And
this again is equivalent to having all items status as 1 (including the
case of no items at all).
The query the refactor_utils_tree generates for the exclude(~Q()) is this:
WHERE NOT (NOT (id IN (SELECT order_id .. WHERE status = 1)), while the
`exclude(items__in)` generates WHERE NOT (id IN (SELECT order_id .. WHERE
NOT status = 1 AND order_id IS NOT NULL)). Thus, the second NOT should be
pushed down to the subquery.
I don't see this as a must fix issue for refactor_utils_tree, but I will
check if this happens to be easy to fix. Another opinion if the
interpretation of the nested exclude is correct would be welcome. These
things tend to get somewhat hard to parse...
--
Ticket URL: <https://code.djangoproject.com/ticket/17600#comment:19>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.