[Django] #29616: Do not ask password in createsuperuser command if used custom user model without password field

81 views
Skip to first unread message

Django

unread,
Jul 31, 2018, 2:53:11 AM7/31/18
to django-...@googlegroups.com
#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=m...@me.com should not ask
password if settings.AUTH_USER_MODEL does not have a password
command ./manage.py createsuperuser --email=m...@me.com --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.

Django

unread,
Jul 31, 2018, 9:28:36 AM7/31/18
to django-...@googlegroups.com
#29616: Do not ask password in createsuperuser command if used custom user model
without password field
--------------------------------------+------------------------------------

Reporter: Semyon Pupkov | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.auth | Version: 2.1
Severity: Normal | Resolution:
Keywords: users | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* type: New feature => Cleanup/optimization
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/29616#comment:1>

Django

unread,
Jul 31, 2018, 10:24:12 PM7/31/18
to django-...@googlegroups.com
#29616: Do not ask password in createsuperuser command if used custom user model
without password field
--------------------------------------+------------------------------------
Reporter: Semyon Pupkov | Owner: oliver
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 2.1

Severity: Normal | Resolution:
Keywords: users | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by oliver):

* status: new => assigned
* owner: nobody => oliver


--
Ticket URL: <https://code.djangoproject.com/ticket/29616#comment:2>

Django

unread,
Aug 1, 2018, 12:29:13 AM8/1/18
to django-...@googlegroups.com
#29616: Do not ask password in createsuperuser command if used custom user model
without password field
--------------------------------------+------------------------------------
Reporter: Semyon Pupkov | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.auth | Version: 2.1

Severity: Normal | Resolution:
Keywords: users | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by oliver):

* owner: oliver => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/29616#comment:3>

Django

unread,
Aug 2, 2018, 6:24:59 PM8/2/18
to django-...@googlegroups.com
#29616: Do not ask password in createsuperuser command if used custom user model
without password field
-------------------------------------+-------------------------------------
Reporter: Semyon Pupkov | Owner: Josh
Type: | Schneier
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 2.1

Severity: Normal | Resolution:
Keywords: users | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Josh Schneier):

* status: new => assigned

* owner: nobody => Josh Schneier


--
Ticket URL: <https://code.djangoproject.com/ticket/29616#comment:2>

Django

unread,
Aug 5, 2018, 2:26:53 PM8/5/18
to django-...@googlegroups.com
#29616: Do not ask password in createsuperuser command if used custom user model
without password field
-------------------------------------+-------------------------------------
Reporter: Semyon Pupkov | Owner: Josh
Type: | Schneier
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 2.1
Severity: Normal | Resolution:
Keywords: users | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


Comment:

[https://github.com/django/django/pull/10269 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29616#comment:3>

Django

unread,
Aug 5, 2018, 2:49:38 PM8/5/18
to django-...@googlegroups.com
#29616: Do not ask password in createsuperuser command if used custom user model
without password field
-------------------------------------+-------------------------------------
Reporter: Semyon Pupkov | Owner: Josh
Type: | Schneier
Cleanup/optimization | Status: closed
Component: contrib.auth | Version: 2.1
Severity: Normal | Resolution: fixed

Keywords: users | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"8b43e9b1af37ab222cbe2964ae13a9203afb9c92" 8b43e9b]:
{{{
#!CommitTicketReference repository=""
revision="8b43e9b1af37ab222cbe2964ae13a9203afb9c92"
Fixed #29616 -- Fixed createsuperuser for user models that don't have a
password field.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29616#comment:4>

Reply all
Reply to author
Forward
0 new messages