In and Range lookups crash when provided to filter() if RHS contains mix of expressions and strings
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.
======================================================================
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).
Change History
(8)
| Description: |
modified (diff)
|
| Cc: |
Simon Charette added
|
| Triage Stage: |
Unreviewed → Accepted
|
| Owner: |
set to Pravin
|
| Status: |
new → assigned
|
| Owner: |
Pravin removed
|
| Status: |
assigned → new
|
| Owner: |
set to JaeHyuckSa
|
| Status: |
new → assigned
|
Suggested patch is to just guard with
hasattr("output_field").