﻿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
36584	Loosen tuple lookup check for rhs subquery field cardinality to allow selecting ForeignObject	Jacob Walls	JaeHyuckSa	"As of the fix for #36431, `values(""user"")` where ""user"" is a multi-column `ForeignObject` now resolves to a `Tuple`, which means we can relax the cardinality check for lookups such as `TupleIn` (introduced in #36149) to get this test case passing:

{{{#!diff
diff --git a/tests/composite_pk/test_filter.py b/tests/composite_pk/test_filter.py
index d7ecfbec11..c4b393d6ea 100644
--- a/tests/composite_pk/test_filter.py
+++ b/tests/composite_pk/test_filter.py
@@ -460,6 +460,11 @@ class CompositePKFilterTests(TestCase):
         queryset = User.objects.filter(comments__in=subquery)
         self.assertSequenceEqual(queryset, (self.user_2,))
 
+    def test_filter_comments_by_users_subquery(self):
+        subquery = Comment.objects.filter(id=3).values(""user"")
+        queryset = Comment.objects.filter(user__in=subquery)
+        self.assertSequenceEqual(queryset, (self.comment_3,))
+
     def test_cannot_cast_pk(self):
         msg = ""Cast expression does not support composite primary keys.""
         with self.assertRaisesMessage(ValueError, msg):
}}}

Currently this gives:
{{{#!py
  File ""/Users/jwalls/django/django/db/models/fields/related_lookups.py"", line 84, in get_prep_lookup
    return super().get_prep_lookup()
           ~~~~~~~~~~~~~~~~~~~~~~~^^
  File ""/Users/jwalls/django/django/db/models/lookups.py"", line 509, in get_prep_lookup
    raise ValueError(
    ...<2 lines>...
    )
ValueError: The QuerySet value for the 'in' lookup must have 2 selected fields (received 1)

----------------------------------------------------------------------
}}}

Indeed, commenting out that `ValueError` allows this test to pass with the fix for #36431, so there should be way to adjust this guard."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed	CompositePrimaryKey		Ready for checkin	1	0	0	0	0	0
