Re: [Django] #35972: Custom lookup example raises TypeError when looked up against a Subquery (was: Custom lookup example raises TypeError when used on a JSONField)

3 views
Skip to first unread message

Django

unread,
Dec 5, 2024, 8:29:58 AM12/5/24
to django-...@googlegroups.com
#35972: Custom lookup example raises TypeError when looked up against a Subquery
-------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Jacob Walls):

* resolution: worksforme =>
* status: closed => new
* summary: Custom lookup example raises TypeError when used on a JSONField
=>
Custom lookup example raises TypeError when looked up against a
Subquery

Comment:

Thanks Sarah for stubbing out a test. Sorry I didn't notice the special
ingredient was Subquery and not JSONField, although I take it there could
be other offenders besides Subquery?

This fails:
{{{#!diff
diff --git a/tests/custom_lookups/tests.py b/tests/custom_lookups/tests.py
index 2f4ea0a9a0..b1681621c6 100644
--- a/tests/custom_lookups/tests.py
+++ b/tests/custom_lookups/tests.py
@@ -249,6 +249,26 @@ class LookupTests(TestCase):
self.assertSequenceEqual(qs1, [a1])
self.assertSequenceEqual(qs2, [a1])

+ def test_custom_lookup_with_subquery(self):
+ class NotEqual(models.Lookup):
+ lookup_name = "ne"
+
+ def as_sql(self, compiler, connection):
+ lhs, lhs_params = self.process_lhs(compiler, connection)
+ rhs, rhs_params = self.process_rhs(compiler, connection)
+ params = lhs_params + rhs_params
+ return "%s <> %s" % (lhs, rhs), params
+
+ author = Author.objects.create(name="Isabella")
+
+ with register_lookup(models.Field, NotEqual):
+ qs = Author.objects.annotate(
+ unknown_age=models.Subquery(
+
Author.objects.filter(age__isnull=True).values("name")
+ )
+ ).filter(unknown_age__ne="Plato")
+ self.assertSequenceEqual(qs, [author])
+
def test_custom_exact_lookup_none_rhs(self):
"""
__exact=None is transformed to __isnull=True if a custom lookup
class
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35972#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages