When sorting Username on People page, an error is triggered due to MySQL

Created on 26 February 2025, about 2 months ago

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');
🐛 Bug report
Status

Needs work

Version

12.4

Component

Code (back-end)

Created by

🇮🇳India hitesh-jain

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024