Opened 2 years ago

Last modified 23 months ago

#26790 assigned Cleanup/optimization

Move BaseUserManager.normalize_email() to AbstractUser

Reported by: Huynh Thanh Tam Owned by: Huynh Thanh Tam
Component: contrib.auth Version: master
Severity: Normal Keywords: normalize_email
Cc: berker.peksag@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In the current code, normalize_username is placed in AbstractBaseUser, but normalize_email currently stay in BaseUserManager for backward-combatibility.
I suggest we move normalize_email logic to AbstractBaseUser for consistency with normalize_username, and raise warning for the original one.

Change History (5)

comment:1 Changed 2 years ago by Huynh Thanh Tam

Status: newassigned

comment:2 Changed 2 years ago by Tim Graham

Summary: Consistency in normalize_email and normalize_usernameMove BaseUserManager.normalize_email() to AbstractUser
Triage Stage: UnreviewedAccepted
Version: 1.10master

If the user has overridden BaseUserManager.normalize_email(), we need to use that implementation during the deprecation period. The idea is similar to the deprecation of ModelAdmin.declared_fieldsets in ebb3e50243448545c7314a1932a9067ddca5960b.

It seems to me the normalize_email() should be moved to AbstractUser (which has the email field) rather than AbstractBaseUser.

comment:3 Changed 2 years ago by Bang Dao

currently BaseUserManager.normalize_email() is a classmethod, from cls we can't get model attribute like manager_instance.model. Thus when we move normalize_email to AbstractUser, I don't know how to make a extendable call to AbstractUser. normalize_email() from classmethod BaseUserManager.normalize_email() for backward compatibility.

comment:4 in reply to:  2 Changed 23 months ago by Berker Peksag

Cc: berker.peksag@… added

It seems to me the normalize_email() should be moved to AbstractUser (which has the email field) rather than AbstractBaseUser.

Note that the username field is also defined in AbstractUser but normalize_username() is implemented in AbstractBaseUser.

comment:5 Changed 23 months ago by Tim Graham

Yes, but AbstractBaseUser.normalize_username() is called on the result of AbstractBaseUser.get_username(). Are you proposing a different organization?

Note: See TracTickets for help on using tickets.
Back to Top