﻿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
36787	In and Range lookups crash when provided to filter() if RHS contains mix of expressions and strings	Jacob Walls	JaeHyuckSa	"The invariance between `__in` and `In` is broken when the right hand side contains a mix of expressions and strings (where the strings are possible literal values). EDIT: replaced draft test case, first version was misleading.
{{{#!diff
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py
index 5b9dd8e5ec..a34d95b8cb 100644
--- a/tests/lookup/tests.py
+++ b/tests/lookup/tests.py
@@ -1855,6 +1855,19 @@ class LookupQueryingTests(TestCase):
                     Season.objects.filter(In(F(""year""), years)).order_by(""pk""), seasons
                 )
 
+    def test_in_lookup_in_filter_text_field(self):
+        self.assertSequenceEqual(
+            # this works...
+            # Season.objects.filter(
+            #     nulled_text_field__in=[F(""nulled_text_field""), ""special_value""]
+            # ),
+            # this doesn't...
+            Season.objects.filter(
+                In(F(""nulled_text_field""), [F(""nulled_text_field""), ""special_value""])
+            ),
+            [self.s2],
+        )
+
     def test_filter_lookup_lhs(self):
         qs = Season.objects.annotate(before_20=LessThan(F(""year""), 2000)).filter(
             before_20=LessThan(F(""year""), 1900),

}}}
{{{#!py
======================================================================
ERROR: test_in_lookup_in_filter_text_field (lookup.tests.LookupQueryingTests.test_in_lookup_in_filter_text_field)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/django/source/tests/lookup/tests.py"", line 1866, in test_in_lookup_in_filter_text_field
    In(F(""nulled_text_field""), [F(""nulled_text_field""), ""special_value""])
  File ""/django/source/django/db/models/lookups.py"", line 35, in __init__
    self.rhs = self.get_prep_lookup()
               ^^^^^^^^^^^^^^^^^^^^^^
  File ""/django/source/django/db/models/lookups.py"", line 517, in get_prep_lookup
    return super().get_prep_lookup()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""/django/source/django/db/models/lookups.py"", line 310, in get_prep_lookup
    Value(prep_value, self.lhs.output_field)
                      ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'F' object has no attribute 'output_field'
}}}
Seems like 089deb82b9ac2d002af36fd36f288368cdac4b53 (5.2) needed the same tweak as 0bfaa55708d402432d44882d9a8e4cb85011472c (5.2)."	Bug	closed	Database layer (models, ORM)	5.2	Normal	fixed		Simon Charette Clifford Gama Varun Kasyap Pentamaraju	Ready for checkin	1	0	0	0	0	0
