#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 <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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.1ff3d2cfd48f7535f4092c7fa55c9f53%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to