Opened 5 years ago

Closed 5 years ago

#29616 closed Cleanup/optimization (fixed)

Do not ask password in createsuperuser command if used custom user model without password field

Reported by: Semyon Pupkov Owned by: Josh Schneier
Component: contrib.auth Version: 2.1
Severity: Normal Keywords: users
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In a case when user model customized as:

from django.contrib.auth.base_user import AbstractBaseUser

class UserManager(BaseUserManager):
    def _create_user(self, portal_user_id, email, **extra_fields):
        del extra_fields['password'] <<-- trick to fix errror

        email = self.normalize_email(email)
        user = self.model(portal_user_id=portal_user_id, email=email, **extra_fields)
        return user

    def create_superuser(self, portal_user_id, email=None, **extra_fields):
        return self._create_user(portal_user_id, email, **extra_fields)

class User(AbstractBaseUser):
    password = None
    last_login = None
    objects = UserManager()

command ./ createsuperuser --email=me@… should not ask password if settings.AUTH_USER_MODEL does not have a password
command ./ createsuperuser --email=me@… --noinput should not pass a password to create_superuser method


Traceback (most recent call last):
  File "./", line 15, in <module>
  File "/app/.venv/lib/python3.7/site-packages/django/core/management/", line 371, in execute_from_command_line
  File "/app/.venv/lib/python3.7/site-packages/django/core/management/", line 365, in execute
  File "/app/.venv/lib/python3.7/site-packages/django/core/management/", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.venv/lib/python3.7/site-packages/django/contrib/auth/management/commands/", line 59, in execute
    return super().execute(*args, **options)
  File "/app/.venv/lib/python3.7/site-packages/django/core/management/", line 335, in execute
    output = self.handle(*args, **options)
  File "/app/.venv/lib/python3.7/site-packages/django/contrib/auth/management/commands/", line 179, in handle
  File "/app/trc/users/", line 17, in create_superuser
    return self._create_user(portal_user_id, email, **extra_fields)
  File "/app/trc/users/", line 12, in _create_user
    user = self.model(portal_user_id=portal_user_id, email=email, **extra_fields)
  File "/app/.venv/lib/python3.7/site-packages/django/db/models/", line 495, in __init__
    raise TypeError("'%s' is an invalid keyword argument for this function" % kwarg)
TypeError: 'password' is an invalid keyword argument for this function

Change History (4)

comment:1 Changed 5 years ago by Tim Graham

Triage Stage: UnreviewedAccepted
Type: New featureCleanup/optimization

comment:2 Changed 5 years ago by Josh Schneier

Owner: changed from nobody to Josh Schneier
Status: newassigned

comment:3 Changed 5 years ago by Tim Graham

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:4 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 8b43e9b:

Fixed #29616 -- Fixed createsuperuser for user models that don't have a password field.

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