Skip to content

Commit

Permalink
[4.2.x] Fixed #34992 -- Fixed DatabaseFeatures.allows_group_by_select…
Browse files Browse the repository at this point in the history
…ed_pks on MariaDB with ONLY_FULL_GROUP_BY sql mode.

Regression in 041551d.

Backport of 0257426 from main.
  • Loading branch information
nathanielconroy authored and felixxm committed Nov 27, 2023
1 parent bac9e94 commit 450d518
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion django/db/backends/mysql/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class DatabaseFeatures(BaseDatabaseFeatures):
empty_fetchmany_value = ()
allows_group_by_selected_pks = True
related_fields_match_type = True
# MySQL doesn't support sliced subqueries with IN/ALL/ANY/SOME.
allow_sliced_subqueries_with_in = False
Expand Down Expand Up @@ -348,3 +347,9 @@ def can_rename_index(self):
if self.connection.mysql_is_mariadb:
return self.connection.mysql_version >= (10, 5, 2)
return True

@cached_property
def allows_group_by_selected_pks(self):
if self.connection.mysql_is_mariadb:
return "ONLY_FULL_GROUP_BY" not in self.connection.sql_mode
return True
4 changes: 4 additions & 0 deletions docs/releases/4.2.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ Bugfixes

* Fixed a regression in Django 4.2 where checkboxes in the admin would be
centered on narrower screen widths (:ticket:`34994`).

* Fixed a regression in Django 4.2 that caused a crash of querysets with
aggregations on MariaDB when the ``ONLY_FULL_GROUP_BY`` SQL mode was enabled
(:ticket:`34992`).
18 changes: 18 additions & 0 deletions tests/backends/mysql/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,21 @@ def test_allows_auto_pk_0(self):
_connection.sql_mode = {"NO_AUTO_VALUE_ON_ZERO"}
database_features = DatabaseFeatures(_connection)
self.assertIs(database_features.allows_auto_pk_0, True)

def test_allows_group_by_selected_pks(self):
with mock.MagicMock() as _connection:
_connection.mysql_is_mariadb = False
database_features = DatabaseFeatures(_connection)
self.assertIs(database_features.allows_group_by_selected_pks, True)

with mock.MagicMock() as _connection:
_connection.mysql_is_mariadb = False
_connection.sql_mode = {}
database_features = DatabaseFeatures(_connection)
self.assertIs(database_features.allows_group_by_selected_pks, True)

with mock.MagicMock() as _connection:
_connection.mysql_is_mariadb = True
_connection.sql_mode = {"ONLY_FULL_GROUP_BY"}
database_features = DatabaseFeatures(_connection)
self.assertIs(database_features.allows_group_by_selected_pks, False)

0 comments on commit 450d518

Please sign in to comment.