Opened 9 months ago
Closed 9 months ago
#35287 closed Bug (duplicate)
manage createsuperuser too restrictive
Reported by: | Matthew Pava | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | 5.0 |
Severity: | Normal | Keywords: | createsuperuser username |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a custom user model inheriting from AbstractUser
. I set username = None
because I don't care about usernames. I care about emails. Anyway, whenever I do that, I get an error message from the manage createsuperuser
command.
For example:
TypeError: UserManager.create_superuser() missing 1 required positional argument: 'username' ValueError: The given username must be set TypeError: StudentManager._create_user() takes from 1 to 3 positional arguments but 4 were given
This has forced me to customize the UserManager
:
class MyUserManager(UserManager): def _create_user(self, username=None, email=None, password=None, **extra_fields): email = self.normalize_email(email) user = self.model(email=email, **extra_fields) user.password = make_password(password) user.save(using=self._db) return user def create_superuser(self, email=None, password=None, **extra_fields): super().create_superuser(email, password, **extra_fields)
My rationale for not having or requiring a username is that all valid email addresses are unique. I think the createsuperuser
command ought to be more lenient in regard to the username
field.
Note:
See TracTickets
for help on using tickets.
Duplicate of #26412.