#35287: manage createsuperuser too restrictive
-------------------------------------+-------------------------------------
Reporter: Matthew | Owner: nobody
Pava |
Type: Bug | Status: new
Component: Core | Version: 5.0
(Management commands) | Keywords: createsuperuser
Severity: Normal | username
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35287>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.