Change the database schema for the User entity and add a unique key for the email

Created on 14 April 2010, over 14 years ago
Updated 30 March 2023, over 1 year ago

The database schema for {user} does not require that email addresses are unique, and user_save() does not prevent saving multiple users with the same address. However, when user with a non-unique address submits the account form on user/123/edit, the form validation fails with the following error message:

The e-mail address c960657@example.com is already taken.

The error occurs, even if the registered mail address has not been changed, i.e. this prevents the user from changing other parts of the profile.

I know that other parts of Drupal does not properly handle duplicate email addresses, e.g. the lost password feature, but we should either fix those parts or enforce the uniqueness in the database schema and/or in user_save().

📌 Task
Status

Closed: won't fix

Version

10.1

Component
User system 

Last updated about 5 hours ago

Created by

🇩🇰Denmark c960657

Live updates comments and jobs are added and updated live.
  • Needs framework manager review

    It is used to alert the framework manager core committer(s) that an issue significantly impacts (or has the potential to impact) multiple subsystems or represents a significant change or addition in architecture or public APIs, and their signoff is needed (see the governance policy draft for more information). If an issue significantly impacts only one subsystem, use Needs subsystem maintainer review instead, and make sure the issue component is set to the correct subsystem.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India nikhil_110

    Try to fixed #39 Cc Failed

  • 🇮🇳India nikhil_110

    Fixed #41 Cc Failed.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +    $random_generator = new Random();
     
         $edit = [];

    The UserRegistrationTest class has the randomMachineName() and the randomString() methods. Using the Random class should not be necessary.

  • 🇦🇺Australia dpi Perth, Australia

    I still stand by my comment from #23.

    I dont think we should be enforcing database level uniqueness, defer to validators and contrib to solve these issues.

    Shall we get a framework maintainer opinion on this? (currently: Moshe)

  • 🇸🇰Slovakia poker10

    I think there are still some unresolved questions, for example the one from #27:

    What will occur if there are duplicates when the schema change is implemented?

    It is also important to think about case-sensitivity. In MySQL unique columns are case insensitive by default, so you cannot have test@test.com and TEST@test.com. On the other side, in PostgreSQL, these are case sensitive and by default it will allow test@test.com and TEST@test.com in the unique columns. This can cause another confusion if not handled properly.

    In my opinion, the uniqueness validation could remain only in code. There are lot of contrib modules creating weird email addresses just to workaround the need of the email address, or even saving empty email addresses and this change could potentially break all these.

  • 🇺🇸United States AaronBauman Philadelphia

    Should we get rid of all other database constraints as well then?
    Why do we unique constraints for UUID or username?

    Seems like maybe we need to define a decision making criteria for when database constraints are warranted.

  • Status changed to Closed: won't fix over 1 year ago
  • 🇺🇸United States moshe weitzman Boston, MA

    Hi all - user module maintainer here.

    If I were designing Drupal from scratch, I would certainly put a uniqueness constraint in the DB. But we are now 22 years into Drupal's life, and I think that ship has sailed. We dont want to disrupt existing sites so much. Folks who want to add this constraint to their DB are free to do so via schema alter. See UserStorageSchema::getEntitySchema().

    Lets focus improving our add/edit validators as needed. And lets do that in other issues.

    I respectfully close this long-standing issue.

  • 🇳🇱Netherlands daffie

    I think this functionality would be great for a contrib module.

Production build 0.71.5 2024