Setting primary email overwrites User.username value

I encountered an issue when sentry overwrites User.username field after setting a primary email, which is unwanted in some cases.
I use sentry integrated with LDAP server and the authentication based on usernames (doesn’t contain emails at all), so such change breaks the user access.

For example, the case

  1. User account is created automatically based on ldap info on first login
  2. After that the user sets a primary email
  3. He accidentally can’t be authenticated next time due to described behavior

Here is the code which does that.

I would expect that setting primary email will change only the field. Is it really necessary to overwrite username with an email?

It would be nice to sort it out. Thanks in advance.

To us, usernames are legacy which is why we are trying to set it. All authentication is done by email address now and has been this way for a while.

When a new user signs up, they’re not given an option for a username, and we keep the username and email fields in sync when possible.

So for your case, assume the username column doesn’t exist and only use email for auth.