Support exact lookups where lhs is CompositePrimaryKey and rhs is Subquery
This query is not currently supported (models drawn from composite_pk test suite):
subquery = Subquery(User.objects.filter(pk=OuterRef("pk")).values("pk"))
queryset = Comment.objects.filter(pk=subquery)
File "/django/source/django/db/models/fields/tuple_lookups.py", line 56, in get_prep_lookup
self.check_rhs_is_supported_expression()
File "/django/source/django/db/models/fields/tuple_lookups.py", line 79, in check_rhs_is_supported_expression
raise ValueError(
ValueError: 'exact' subquery lookup of 'pk' only supports OuterRef and QuerySet objects (received 'Subquery')
The version without explicit Subquery
(and adding [:1]
) also fails:
File "/django/source/django/db/models/lookups.py", line 384, in get_prep_lookup
raise ValueError(
ValueError: The QuerySet value for the exact lookup must have 2 selected fields (received 1)
On Oracle the failure looks like this, but this is probably a separate issue:
django.db.utils.DatabaseError: ORA-01796: this operator cannot be used with lists
Help: https://docs.oracle.com/error-help/db/ora-01796/
PR to kick off discussion addresses all but the Oracle failure, which might worth looking at separately, perhaps a deeper issue?
Change History
(14)
Cc: |
Csirmaz Bendegúz added
|
Triage Stage: |
Unreviewed → Accepted
|
Summary: |
Support queries where lhs is CompositePrimaryKey and rhs is Subquery → Support exact lookups where lhs is CompositePrimaryKey and rhs is Subquery
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
On the PR Simon suggested fixing this closer to the root of the problems with Subquery resolution. If someone else has capacity, feel free to reassign, it might be a while before I can get to it.