#33655: Unnecessary column in a GROUP BY clause with QuerySet.exists()
-------------------------------------+-------------------------------------
     Reporter:  Marc Perrin          |                    Owner:  Marc
         Type:                       |  Perrin
  Cleanup/optimization               |                   Status:  assigned
    Component:  Database layer       |                  Version:  4.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  exists group by      |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

 Replying to [comment:8 Marc Perrin]:
 > Yeah, I guess I can do that, with Simon's suggestion the whole thing
 should be straightforward enough.
 > I'll take the ticket - I'll have to look up the contribution guide etc.
 / especially about the tests, as I haven't really contributed before.

 Great, thanks! In this ticket we are forced to check a generated SQL, IMO
 it's fine to add assertions to an existing test e.g.
 
`aggregation.tests.AggregateTestCase.test_aggregation_subquery_annotation_exists`:
 {{{#!python
         with self.assertNumQueries(1) as ctx:
             self.assertTrue(publisher_qs.exists())
         sql = ctx[0]["sql"]
         self.assertIn("SELECT 1 ", sql)
         self.assertNotIn("(1)", sql)
         # There is just one GROUP BY clause (zero commas means at most one
         # clause).
         self.assertEqual(sql[sql.index("GROUP BY") :].count(", "), 0)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33655#comment:10>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018061af5847-f23c9a57-4150-485a-b758-5c5cb006daab-000000%40eu-central-1.amazonses.com.

Reply via email to