Code

Opened 5 years ago

Closed 5 years ago

Last modified 17 months ago

#11090 closed (wontfix)

Query.group_by no longer supports MySQL specific behaviour

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

Description

I used to be able to do:

qs = Model.objects.extra(select={'foo': 'custom_aggregate()'}, tables=['table'])
qs.query.group_by = ['table.column']

This generated a query like:

SELECT model.a, model.b, custom_aggregate() AS foo FROM model, table GROUP BY table.column

As far as I understand, this is exploiting MySQL specific behaviour that supports collapsing multiple values within a group into a single return row, rather than enforcing every column to be either listed in GROUP BY, or be an aggregate, as Postgre does, for example.

Now, with the changes from r9805 and later also r9838, when using any kind of group_by value at all, the resulting query will actually list all select, select_related and extra_select fields in the GROUP BY clause, meaning my query is now:

SELECT model.a, model.b, custom_aggregate() AS foo FROM model, table GROUP BY table.column, model.a, model.b, foo

I realize that group_by is internal API and Django may not want to support this at all, but in case the change was unintentional, I thought I'd bring it up.

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by miracle2k

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Query.group_by behaviour no longer supports MySQL specific behaviour to Query.group_by no longer supports MySQL specific behaviour

comment:2 Changed 5 years ago by russellm

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

The change was intentional, and was necessary to implement aggregates. As you noted - group_by is a Django internal, and backwards incompatibility is in no way guaranteed.

comment:3 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.