#29338: Can't use OuterRef in union Subquery
-------------------------------------+-------------------------------------
Reporter: Matthew | Owner: nobody
Pava |
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When you make a QuerySet using the `union` method or the `|` operator, the
QuerySet passed into the `union` method cannot reference `OuterRef` even
when wrapped with `Subquery`.
For example:
{{{
cls = Document.objects.filter(
checklist__isnull=False,
part=OuterRef('id')
).values('checklist__customer', 'created')
ots = Document.objects.filter(
ownershiptransfer__isnull=False,
part=OuterRef('id')
).values('ownershiptransfer__ship_target__contact', 'created')
return self.annotate(
owner=Subquery(cls.union(ots).values('owner')[:1])
)
}}}
Returns this error:
{{{
ValueError
This queryset contains a reference to an outer query and may only be used
in a subquery.
}}}
I get the same error with this statement:
{{{
return self.annotate(
owner=Subquery((cls | ots).values('owner')[:1])
)
}}}
(As an aside, I also get an error when I try to apply an `order_by`
clause.)
--
Ticket URL: <https://code.djangoproject.com/ticket/29338>
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/049.c28ef28c1e096380f89084b82983f494%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.