Calling .dates on a annotated queryset gives wrong sql
Example models
class Photo(models.Model):
title = models.CharField(max_length=30)
class Gallery(models.Model):
title = models.CharField(max_length=30)
photos = models.ManyToManyField(Photo)
date_published = models.DateField()
Query:
from django.db import connection
from django.db.models import Count
Gallery.objects.dates('date_published', 'year')
print connection.queries[-1]
Gallery.objects.annotate(photo_count=Count('photos__id')).dates('date_published', 'year')
print connection.queries[-1]
Component: |
Uncategorized → ORM aggregation
|
Owner: |
nobody removed
|
Has patch: |
set
|
Triage Stage: |
Unreviewed → Accepted
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
Component: |
ORM aggregation → Database layer (models, ORM)
|
(In [9839]) Fixed #10248 -- Corrected handling of the GROUP BY clause when using a DateQuerySet. Thanks to Alex Gaynor for the report and patch.