1
0
mirror of https://github.com/django/django.git synced 2025-03-13 10:50:55 +00:00

[5.1.x] Fixed #35603 -- Prevented F.__contains__() from hanging.

Regression in 94b6f101f7dc363a8e71593570b17527dbb9f77f.

Backport of 6b3f55446fdc62bd277903fd188a1781e4d92d29 from main.
This commit is contained in:
Simon Charette 2024-07-17 14:52:08 -04:00 committed by Sarah Boyce
parent 5eef80b56e
commit 8fb7d30456
2 changed files with 10 additions and 0 deletions

View File

@ -884,6 +884,11 @@ class F(Combinable):
def __getitem__(self, subscript):
return Sliced(self, subscript)
def __contains__(self, other):
# Disable old-style iteration protocol inherited from implementing
# __getitem__() to prevent this method from hanging.
raise TypeError(f"argument of type '{self.__class__.__name__}' is not iterable")
def resolve_expression(
self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False
):

View File

@ -1302,6 +1302,11 @@ class FTests(SimpleTestCase):
self.assertNotEqual(f, value)
self.assertNotEqual(value, f)
def test_contains(self):
msg = "argument of type 'F' is not iterable"
with self.assertRaisesMessage(TypeError, msg):
"" in F("name")
class ExpressionsTests(TestCase):
def test_F_reuse(self):