#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070193970335da-6b69a52c-5a1f-414d-8b5d-584a5006390f-000000%40eu-central-1.amazonses.com.

Reply via email to