#29616: Do not ask password in createsuperuser command if used custom user model
without password field
-----------------------------------------+------------------------
               Reporter:  Semyon Pupkov  |          Owner:  nobody
                   Type:  New feature    |         Status:  new
              Component:  contrib.auth   |        Version:  2.1
               Severity:  Normal         |       Keywords:  users
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 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)
         user.save(using=self._db)
         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 ./manage.py createsuperuser [email protected] should not ask
 password if settings.AUTH_USER_MODEL does not have a password
 command  ./manage.py createsuperuser [email protected] --noinput should
 not pass a password to create_superuser method

 Traceback
 {{{
 Traceback (most recent call last):
   File "./manage.py", line 15, in <module>
     execute_from_command_line(sys.argv)
   File "/app/.venv/lib/python3.7/site-
 packages/django/core/management/__init__.py", line 371, in
 execute_from_command_line
     utility.execute()
   File "/app/.venv/lib/python3.7/site-
 packages/django/core/management/__init__.py", line 365, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/app/.venv/lib/python3.7/site-
 packages/django/core/management/base.py", line 288, in run_from_argv
     self.execute(*args, **cmd_options)
   File "/app/.venv/lib/python3.7/site-
 packages/django/contrib/auth/management/commands/createsuperuser.py", line
 59, in execute
     return super().execute(*args, **options)
   File "/app/.venv/lib/python3.7/site-
 packages/django/core/management/base.py", line 335, in execute
     output = self.handle(*args, **options)
   File "/app/.venv/lib/python3.7/site-
 packages/django/contrib/auth/management/commands/createsuperuser.py", line
 179, in handle
 
self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
   File "/app/trc/users/models.py", line 17, in create_superuser
     return self._create_user(portal_user_id, email, **extra_fields)
   File "/app/trc/users/models.py", 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/base.py",
 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
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29616>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.611ab6da2ab302211f863e8300f0c435%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to