#35603: "string" in F("...") hangs
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Lufafa
| Joshua
Type: Bug | Status: assigned
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
Tim, given we don't actually support it I think raising a `TypeError`
might effectively be more appropriate. I tried skimming the Python docs to
understand if doing so would be against any established ''protocol'' and I
couldn't find anyway.
To make sure we're aligned, you were thinking of something like
{{{#!diff
diff --git a/django/db/models/expressions.py
b/django/db/models/expressions.py
index dcba973ff4..1d16781959 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -884,6 +884,11 @@ def __repr__(self):
def __getitem__(self, subscript):
return Sliced(self, subscript)
+ def __contains__(self, other):
+ # Disable old-style iteration protocol inherited from
implementing
+ # `__getitem__` for slicing to prevent containment checks 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
):
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/35603#comment:4>