Skip to content

Commit 0257426

Browse files
nathanielconroyfelixxm
authored andcommitted
Fixed #34992 -- Fixed DatabaseFeatures.allows_group_by_selected_pks on MariaDB with ONLY_FULL_GROUP_BY sql mode.
Regression in 041551d.
1 parent 0203771 commit 0257426

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

django/db/backends/mysql/features.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class 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

docs/releases/4.2.8.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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`).

tests/backends/mysql/test_features.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)