Problem/Motivation
When using the People page (admin/people) , sorting by Username triggers a SQL error when MySQL's ONLY_FULL_GROUP_BY mode is enabled. This is a common setting in modern MySQL configurations to enforce strict GROUP BY behavior, ensuring all non-aggregated fields in SELECT statements are included in the GROUP BY clause.
Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'db.profile__profile_name.profile_name_value' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Steps to reproduce
1. Go to People page i.e `admin/people` that uses the Profile Entity sort.
2. Click on "Sort" for Username field.
3. See the SQL error related to `ONLY_FULL_GROUP_BY` mode. This error happens only when the database is MySQL, as on MySQL ONLY_FULL_GROUP_BY SQL mode is enabled by default, but on MariaDB is disabled by default.
Error :
Drupal\Core\Database\DatabaseExceptionWrapper: Exception in People[user_admin_people]: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'db.profile__profile_name.profile_name_value' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Proposed resolution
Add the `profile_name_value` field to the `GROUP BY` clause in the `ProfileEntitySortable` class:
// Add the field to the GROUP BY clause to avoid SQL error.
$query->addGroupBy('profile__profile_name.profile_name_value');
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | username_sorting_error-3509053-2.patch | 982 bytes | hitesh-jain |
Comments
Comment #2
hitesh-jain commentedComment #3
hitesh-jain commentedOpen social PR : https://github.com/goalgorilla/open_social/pull/4296