Changes between Initial Version and Version 1 of Ticket #34978, comment 4


Ignore:
Timestamp:
Nov 20, 2023, 9:26:03 AM (13 months ago)
Author:
Simon Charette

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #34978, comment 4

    initial v1  
    4343> This one's interesting because we can't dig into RawSQL to determine whether it's valid in a GROUP BY or not.
    4444
    45 That's right David, it's the crux of the issue.
     45That's right David, it's the crux of the issue. Since it's a blackbox the ORM must choose between grouping or not by the column and since most `RawSQL` usage are assumed to not be aggregation it determines that it must do so.
    4646
    4747The reason why 041551d716b69ee7c81199eee86a2d10a72e15ab broke the reported use that is that prior to this change the ORM supported a non-standard feature of MySQL [https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html disabled in recent versions] that allowed grouping solely by the primary key of the first entry in `FROM`. It's important to note that using `RawSQL` to aggregate was only working on MySQL due to this feature and never worked on any of the other backends that follow the functional dependency detection in `GROUP BY` clauses as specified by the `SQL:1999` standard.
     
    53531. Revert the changes made in 041551d716b69ee7c81199eee86a2d10a72e15ab while making `allows_group_by_pk` based on the absence of `ONLY_FULL_GROUP_BY`. Note that this won't resolve the aggregation over the annotation of a dependant subquery but will restore the usage of `RawSQL` for aggregation on MySQL only when `ONLY_FULL_GROUP_BY` is disabled.
    54542. 1 + adjustments to the `allows_group_by_pk` to special case dependant subquery annotations
    55 3. Adjust the 4.2 existing release notes about this change to let them know that this version of Django removed support for doing `RawSQL` aggregations on MySQL and that they should use proper expressions instead going forward.
     553. Adjust the 4.2 existing release notes about this change to better communicate that this version of Django removed support for doing `RawSQL` aggregations on MySQL and that they should use proper expressions instead going forward.
    5656
    5757Due to lack of demonstration that some aggregates or window function cannot be expressed using the advanced ORM primitives, that non-`ONLY_FULL_GROUP_BY` model is a non standard MySQL feature that is not enabled by default since 8.0, and that this change happen to standardize the usage of `RawSQL` for aggregations on all backends I'd be inclined to go with 3.
Back to Top