﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36210	Support exact lookups where lhs is CompositePrimaryKey and rhs is Subquery	Jacob Walls	Jacob Walls	"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)
}}}
----
{{{#!py
  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:

{{{#!py
django.db.utils.DatabaseError: ORA-01796: this operator cannot be used with lists
Help: https://docs.oracle.com/error-help/db/ora-01796/
}}}
----
[https://github.com/django/django/pull/19206 PR] to kick off discussion addresses all but the Oracle failure, which might worth looking at separately, perhaps a deeper issue?"	New feature	closed	Database layer (models, ORM)	5.2	Normal	fixed		Csirmaz Bendegúz	Ready for checkin	1	0	0	0	0	0
