#35972: Custom lookup example raises TypeError when looked up against a Subquery
-------------------------------------+-------------------------------------
     Reporter:  Jacob Walls          |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  regex, mysql         |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

 * component:  Documentation => Database layer (models, ORM)
 * keywords:   => regex, mysql

Comment:

 I originally framed it as a documentation issue, given that a
 cleanup/optimization to harden this is probably blocked on a DEP to type-
 annotate the ORM, but here is a test that fails on MariaDB using only
 built in lookups (almost certainly on MySQL as well), so we do have a bug
 in core:

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

 +    def test_regex_lookup_with_subquery(self):
 +        author = Author.objects.create(name="Isabella")
 +
 +        qs = Author.objects.annotate(
 +            unknown_age=models.Subquery(
 +                Author.objects.filter(age__isnull=True).values("name")
 +            )
 +        ).filter(name__regex=models.F("unknown_age"))
 +        self.assertSequenceEqual(qs, [author])
 +
      def test_custom_exact_lookup_none_rhs(self):
          """
          __exact=None is transformed to __isnull=True if a custom lookup
 class
 }}}

 So I think a documentation update is still worthwhile, but after that we
 should leave this open until we fix the regex lookup or do that DEP :D
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35972#comment:4>
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070193974fa165-dd527c62-4951-4980-b092-04305ebf58d2-000000%40eu-central-1.amazonses.com.

Reply via email to