﻿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
37383	"Add support for using F(""pk"") as the LHS of a tuple lookup when the RHS is a Query"	Jacob Walls	Vishy	"The fix for #37291 fixes a hang when using `F(""pk"")` with tuple lookups.

The preliminary fix results in `ValueError`, which is better than a hang. That much can be backported. This issue is for improving on the `ValueError` to return the correct result. In other words, this ticket is for removing these skips on these almost-identical tests:


{{{#!py
# For TupleLookupsTests
    @unittest.expectedFailure
    def test_tuple_in_subquery_lhs_f_pk(self):
        self.assertCountEqual(
            Contact.objects.filter(
                TupleIn(F(""pk""), Contact.objects.values(""customer"").query)
            ),
            Contact.objects.all(),
        )
}}}

{{{#!py
# For CompositePKLookupsTests
    @unittest.expectedFailure
    def test_filter_by_pk_in_rhs_f_object_lhs(self):
        self.assertCountEqual(
            Comment.objects.filter(
                TupleIn(F(""pk""), Comment.objects.values(""pk"").query)
            ),
            Comment.objects.all(),
        )
}}}

See
{{{#!py
======================================================================
ERROR: test_tuple_in_subquery_lhs_f_pk (foreign_object.test_tuple_lookups.TupleLookupsTests.test_tuple_in_subquery_lhs_f_pk)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/Users/jwalls/django/tests/foreign_object/test_tuple_lookups.py"", line 174, in test_tuple_in_subquery_lhs_f_pk
    TupleIn(F(""pk""), Contact.objects.values(""customer"").query)
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""/Users/jwalls/django/django/db/models/lookups.py"", line 36, in __init__
    self.rhs = self.get_prep_lookup()
               ~~~~~~~~~~~~~~~~~~~~^^
  File ""/Users/jwalls/django/django/db/models/fields/tuple_lookups.py"", line 310, in get_prep_lookup
    super(TupleLookupMixin, self).get_prep_lookup()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File ""/Users/jwalls/django/django/db/models/lookups.py"", line 512, in get_prep_lookup
    raise ValueError(
    ...<2 lines>...
    )
ValueError: The QuerySet value for the 'in' lookup must have 1 selected fields (received 2)
}}}

We don't have access to the `query` for resolution of `F(""pk"")` during the `get_prep_lookup()` above, so I'm not immediately sure how to solve this."	Bug	assigned	Database layer (models, ORM)	dev	Normal		CompositePrimaryKey		Unreviewed	0	0	0	0	0	0
