Code

Opened 5 years ago

Closed 5 years ago

Last modified 17 months ago

#10248 closed (fixed)

Calling .dates on a annotated queryset gives wrong sql

Reported by: oyvind Owned by:
Component: Database layer (models, ORM) Version: master
Severity: Keywords: annotate dates queryset
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

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]

Attachments (1)

annotate-dates.diff (1.6 KB) - added by Alex 5 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 5 years ago by oyvind

  • Component changed from Uncategorized to ORM aggregation
  • Needs documentation unset
  • Needs tests unset
  • Owner nobody deleted
  • Patch needs improvement unset

Changed 5 years ago by Alex

comment:2 Changed 5 years ago by oyvind

  • Has patch set
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by ikelly

  • Version changed from 1.0 to SVN

comment:4 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [9839]) Fixed #10248 -- Corrected handling of the GROUP BY clause when using a DateQuerySet. Thanks to Alex Gaynor for the report and patch.

comment:5 Changed 5 years ago by russellm

I'm on a roll tonight - that's 2 messed up commit messages in a row. Apologies to Oyvind Saltvik for misattributing the original report to Alex in the commit message. Still giving thanks to Alex for the patch, though :-)

comment:6 Changed 17 months ago by akaariai

  • Component changed from ORM aggregation to Database layer (models, ORM)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.