#29291: Negated Q expressions across a nullable relationship are not properly
handled by When expressions.
-------------------------------------+-------------------------------------
Reporter: Bo Marchman | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
It's also interesting to see how `.filter(~(Q(score__reviewed=True) |
Q(score__reviewed=None))` behaves
{{{#!sql
SELECT "application"."id"
FROM "application"
WHERE NOT (("application"."id" IN
(SELECT U1."application_id"
FROM "score" U1
WHERE U1."reviewed" = TRUE)
OR "application"."id" IN
(SELECT U0."id"
FROM "application" U0
LEFT OUTER JOIN "score" U1 ON (U0."id" =
U1."application_id")
WHERE (U1."reviewed" IS NULL
AND U0."id" = ("application"."id")))))
}}}
I think the most appropriate solutions at this point is to adjust `When`
SQL compilation to reuse the `Query._add_q` logic. That will make sure the
subquery pushdown is performed if required and make sure implementations
don't diverge.
This should be favorable over implementing a new algorithm specific to
`When` given how `.filter` is already heavily testing the handling of
exclusions across nullable relationships
--
Ticket URL: <https://code.djangoproject.com/ticket/29291#comment:7>
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/062.7fbd5ac80c256ce3d6a3def5e4306b33%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.