#30739: OuterRef in exclude() or ~Q() uses wrong model.
-------------------------------------+-------------------------------------
     Reporter:  Oskar Persson        |                    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
-------------------------------------+-------------------------------------
Changes (by felixxm):

 * cc: Simon Charette (added)
 * version:  2.2 => master
 * stage:  Unreviewed => Accepted


Comment:

 Thanks for the report. `ValueError` was fixed in
 35431298226165986ad07e91f9d3aca721ff38ec. Provided test fails on master
 with
 {{{
 django.db.utils.ProgrammingError: missing FROM-clause entry for table "V0"
 LINE 1: ...(U1."tag_id" = U2."id") WHERE U2."category_id" = ("V0"."id")...
 }}}
 It looks that `OuterRef` resolves to `"V0"."id"` instead of
 `"queries_number"."id"`
 {{{
 SELECT ...
 FROM "queries_number"
 WHERE EXISTS(
     SELECT ...
     FROM "queries_item" V0
     WHERE NOT (V0."id" IN (
         SELECT U1."item_id"
         FROM "queries_item_tags" U1 INNER JOIN "queries_tag" U2 ON
 (U1."tag_id" = U2."id")
         WHERE U2."category_id" = "V0"."id"
     ))
 }}}
 Issue can be reproduce also without annotation
 {{{
 
Number.objects.filter(Exists(Item.objects.exclude(tags__category_id=OuterRef('pk'))))
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30739#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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.ec9d78fbe834de8b0deb0c74615f7125%40djangoproject.com.

Reply via email to