Unhandled exception when trying to register a duplicate username with equality mismatch between php and database layer

Created on 25 June 2024, 3 months ago

Problem/Motivation

In https://www.drupal.org/project/drupal/issues/3415582 🐛 Unhandled exception when trying to register a duplicate username with different case Needs review , an unhandled exception when trying to register a duplicate username with different case was fixed. However, we've now noticed that there are some other cases where the same issue occurs (caused by the same change that caused #3415582). The issue does not only affect case-sensitivity (fixed), but also things like accentuation (e.g. "example" vs. "éxample"). I think there might also be some (not yet known) other edge cases where the same issue occurs. Basically, the issue always occurs if the database layer has a different understanding of equality than the php layer.

I think the issue was introduced by https://www.drupal.org/project/drupal/issues/2478663 📌 UniqueFieldValueValidator works only with single value fields Fixed .

Steps to reproduce

1. Set-up a fresh Drupal 10.3 installation (e.g. on simplytest.me)
2. Log-in as admin
3. Create a user with username "éxample"
4. Create another user with username "example"
5. An unhandled exception occurs:

The website encountered an unexpected error. Try again later.

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'example-en' for key 'user__name': INSERT INTO "users_field_data" ("uid", "langcode", "preferred_langcode", "preferred_admin_langcode", "name", "pass", "mail", "timezone", "status", "created", "changed", "access", "login", "init", "default_langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14); Array ( [:db_insert_placeholder_0] => 3 [:db_insert_placeholder_1] => en [:db_insert_placeholder_2] => en [:db_insert_placeholder_3] => en [:db_insert_placeholder_4] => example [:db_insert_placeholder_5] => $2y$10$h3YBVBuf9CTaL0qk6WpjX.WTmPdNpYLbeEQvpJxVRGAGBOkPNtAqu [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => UTC [:db_insert_placeholder_8] => 1 [:db_insert_placeholder_9] => 1719306986 [:db_insert_placeholder_10] => 1719306986 [:db_insert_placeholder_11] => 0 [:db_insert_placeholder_12] => 0 [:db_insert_placeholder_13] => [:db_insert_placeholder_14] => 1 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php). 

Remaining tasks

- Propose a resolution
- Implement the fix

🐛 Bug report
Status

Active

Version

10.3

Component
User system 

Last updated 1 day ago

Created by

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

Comments & Activities

Production build 0.71.5 2024