[Django] #25009: create_user(..., is_staff=True) raises TypeError multiple values for keyword argument 'is_staff'

50 views
Skip to first unread message

Django

unread,
Jun 19, 2015, 4:41:49 PM6/19/15
to django-...@googlegroups.com
#25009: create_user(..., is_staff=True) raises TypeError multiple values for
keyword argument 'is_staff'
------------------------------+--------------------
Reporter: allcaps | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+--------------------
When I do:

{{{
>>> from django.contrib.auth.models import User
>>> user = User.objects.create_user('test', email='te...@example.com',
password='password', is_staff=True)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/coen/git/prive/tvdordrecht.nl/env/lib/python2.7/site-
packages/django/contrib/auth/models.py", line 183, in create_user
**extra_fields)
TypeError: _create_user() got multiple values for keyword argument
'is_staff'
}}}

Expected:

{{{
>>> user.is_staff
True
}}}

From StackOverflow:
http://stackoverflow.com/questions/30711544/create-staff-user-in-
django/30946633#30946633


Related
https://github.com/bak1an/django/commit/dc2f67679712412e2f8bdfbecc340f796d6dbc24
https://code.djangoproject.com/ticket/20541

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

Django

unread,
Jun 19, 2015, 5:20:17 PM6/19/15
to django-...@googlegroups.com
#25009: create_user(..., is_staff=True) raises TypeError multiple values for
keyword argument 'is_staff'
------------------------------+------------------------------------

Reporter: allcaps | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
------------------------------+------------------------------------
Changes (by bmispelon):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

I can indeed reproduce the issue.

Interestingly, prior to cab333cb16656cbb7d2bcfb06b2f7aeab9bac7af (which
landed in 1.6), doing `User.objects.create_user(..., is_staff=True)`
actually worked, but `User.objects.create_superuser(..., is_staff=False)`
would raise a similar error to what we have now.

I think the fix should be to allow these parameters to be passed. It can
lead to weird code like `User.objects.create_superuser(...,
is_superuser=False)` but I don't think we should code against that.

The fix is then quite straighforward:
{{{#!python
def create_user(self, username, email=None, password=None,
**extra_fields):
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
return self._create_user(username, email, password,
**extra_fields)

def create_superuser(self, username, email, password, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
return self._create_user(username, email, password,
**extra_fields)
}}}

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

Django

unread,
Jun 19, 2015, 7:07:20 PM6/19/15
to django-...@googlegroups.com
#25009: create_user(..., is_staff=True) raises TypeError multiple values for
keyword argument 'is_staff'
------------------------------+------------------------------------

Reporter: allcaps | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
------------------------------+------------------------------------

Comment (by allcaps):

Seems like we can have a cheeseburger without cheese :). Forgiveness is
cool. But we can also raise an error for the superuser.

{{{


def create_user(self, username, email=None, password=None,
**extra_fields):
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
return self._create_user(username, email, password, **extra_fields)

def create_superuser(self, username, email, password, **extra_fields):

if extra_fields.has_key('is_staff') and extra_fields.get('is_staff')
is False:
raise ValueError('Superuser needs to be staff. Do not set
`is_staff`.')
if extra_fields.has_key('is_superuser') and
extra_fields.get('is_superuser') is False:
raise ValueError('Superuser needs to be superuser. Do not set
`is_superuser`.')


extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
return self._create_user(username, email, password, **extra_fields)
}}}

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

Django

unread,
Jun 19, 2015, 11:25:30 PM6/19/15
to django-...@googlegroups.com
#25009: create_user(..., is_staff=True) raises TypeError multiple values for
keyword argument 'is_staff'
------------------------------+------------------------------------
Reporter: allcaps | Owner: pahko
Type: Bug | Status: assigned
Component: contrib.auth | Version: 1.8

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
------------------------------+------------------------------------
Changes (by pahko):

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


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

Django

unread,
Jun 20, 2015, 12:36:47 AM6/20/15
to django-...@googlegroups.com
#25009: create_user(..., is_staff=True) raises TypeError multiple values for
keyword argument 'is_staff'
------------------------------+------------------------------------
Reporter: allcaps | Owner: pahko
Type: Bug | Status: assigned
Component: contrib.auth | Version: 1.8

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
------------------------------+------------------------------------
Changes (by pahko):

* has_patch: 0 => 1


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

Django

unread,
Jun 22, 2015, 11:39:53 AM6/22/15
to django-...@googlegroups.com
#25009: create_user(..., is_staff=True) raises TypeError multiple values for
keyword argument 'is_staff'
------------------------------+------------------------------------
Reporter: allcaps | Owner: pahko
Type: Bug | Status: closed
Component: contrib.auth | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"e75b614640c206bf6d0b1c9d32c54434ea719582" e75b6146]:
{{{
#!CommitTicketReference repository=""
revision="e75b614640c206bf6d0b1c9d32c54434ea719582"
Fixed #25009 -- Allowed User.objects.create_user(...,is_staff=True) to
work.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25009#comment:5>

Reply all
Reply to author
Forward
0 new messages