File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 66
77class DatabaseFeatures (BaseDatabaseFeatures ):
88 empty_fetchmany_value = ()
9- allows_group_by_selected_pks = True
109 related_fields_match_type = True
1110 # MySQL doesn't support sliced subqueries with IN/ALL/ANY/SOME.
1211 allow_sliced_subqueries_with_in = False
@@ -319,3 +318,9 @@ def supports_expression_defaults(self):
319318 def has_native_uuid_field (self ):
320319 is_mariadb = self .connection .mysql_is_mariadb
321320 return is_mariadb and self .connection .mysql_version >= (10 , 7 )
321+
322+ @cached_property
323+ def allows_group_by_selected_pks (self ):
324+ if self .connection .mysql_is_mariadb :
325+ return "ONLY_FULL_GROUP_BY" not in self .connection .sql_mode
326+ return True
Original file line number Diff line number Diff line change @@ -27,3 +27,7 @@ Bugfixes
2727
2828* Fixed a regression in Django 4.2 where checkboxes in the admin would be
2929 centered on narrower screen widths (:ticket:`34994`).
30+
31+ * Fixed a regression in Django 4.2 that caused a crash of querysets with
32+ aggregations on MariaDB when the ``ONLY_FULL_GROUP_BY`` SQL mode was enabled
33+ (:ticket:`34992`).
Original file line number Diff line number Diff line change @@ -28,3 +28,21 @@ def test_allows_auto_pk_0(self):
2828 _connection .sql_mode = {"NO_AUTO_VALUE_ON_ZERO" }
2929 database_features = DatabaseFeatures (_connection )
3030 self .assertIs (database_features .allows_auto_pk_0 , True )
31+
32+ def test_allows_group_by_selected_pks (self ):
33+ with mock .MagicMock () as _connection :
34+ _connection .mysql_is_mariadb = False
35+ database_features = DatabaseFeatures (_connection )
36+ self .assertIs (database_features .allows_group_by_selected_pks , True )
37+
38+ with mock .MagicMock () as _connection :
39+ _connection .mysql_is_mariadb = False
40+ _connection .sql_mode = {}
41+ database_features = DatabaseFeatures (_connection )
42+ self .assertIs (database_features .allows_group_by_selected_pks , True )
43+
44+ with mock .MagicMock () as _connection :
45+ _connection .mysql_is_mariadb = True
46+ _connection .sql_mode = {"ONLY_FULL_GROUP_BY" }
47+ database_features = DatabaseFeatures (_connection )
48+ self .assertIs (database_features .allows_group_by_selected_pks , False )
You can’t perform that action at this time.
0 commit comments