#30771: Filtering on query result overrides GROUP BY of internal query
-------------------------------------+-------------------------------------
Reporter: Aur Saraf | Owner: James
| Timmins
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, | Triage Stage: Accepted
annotation, filter, groupby, |
aggregate, aggregation |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by James Timmins):
Thanks so much for the help Simon! This is a great jumping-off point.
There's something that I'm unclear about, which perhaps you can shed some
light on. While I was able to replicate the bug with 2.2, when I try to
create a test on Master to validate the bug, the group-by behavior seems
to have changed.
Here's the test that I created:
{{{
def test_exact_selected_field_rhs_subquery(self):
author_1 = Author.objects.create(name='one')
author_2 = Author.objects.create(name='two')
max_ids =
Author.objects.filter(alias__isnull=True).values('alias').annotate(m=Max('id')).values('m')
authors = Author.objects.filter(id=max_ids[:1])
self.assertFalse(str(max_ids.query)) # This was just to force the
test-runner to output the query.
self.assertEqual(authors[0], author_2)
}}}
And here's the resulting query:
{{{
SELECT MAX("lookup_author"."id") AS "m" FROM "lookup_author" WHERE
"lookup_author"."alias" IS NULL GROUP BY "lookup_author"."alias",
"lookup_author"."name"
}}}
It no longer appears to be grouping by the 'alias' field listed in the
initial `.values()` preceeding the `.annotate()`. I looked at the docs and
release notes to see if there was a behavior change, but didn't see
anything listed.
Do you know if I'm just misunderstanding what's happening here? Or does
this seem like a possible regression?
--
Ticket URL: <https://code.djangoproject.com/ticket/30771#comment:5>
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/068.b6ebec92d059fbf92e3798b2115a251a%40djangoproject.com.