#33808: Count manytomany__in produces wrong SQL
-------------------------------------+-------------------------------------
     Reporter:  Fabio Zoratti        |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  database, count,     |             Triage Stage:
  query, orm                         |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Fabio Zoratti):

 I used `git bisect` to find the commit that broke the code. The commit is

 {{{

 commit 3a505c70e7b228bf1212c067a8f38271ca86ce09 (HEAD, refs/bisect/bad)
 Author: Simon Charette <charett...@gmail.com>
 Date:   Wed Mar 6 01:24:41 2019 -0500

     Refs #27149, #29542 -- Simplified subquery parentheses wrapping logic.
 }}}

 The diff clearly shows that some parenthesis are being removed from the
 query

 {{{
 git show 3a505c70e7b228bf1212c067a8f38271ca86ce09
 diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py
 index e78ffdf390..910291094e 100644
 --- a/django/db/models/lookups.py
 +++ b/django/db/models/lookups.py
 @@ -89,8 +89,7 @@ class Lookup:
              value = self.apply_bilateral_transforms(value)
              value = value.resolve_expression(compiler.query)
          if hasattr(value, 'as_sql'):
 -            sql, params = compiler.compile(value)
 -            return '(' + sql + ')', params
 +            return compiler.compile(value)
          else:
              return self.get_db_prep_lookup(value, connection)

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33808#comment:1>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/010701819757ec0d-d23ef3b4-0c2d-4d0a-98eb-ffc21415257b-000000%40eu-central-1.amazonses.com.

Reply via email to