Custom User class -> createsuperuser asks for Username twice

175 views
Skip to first unread message

Chris Pagnutti

unread,
Oct 18, 2012, 7:38:05 PM10/18/12
to django...@googlegroups.com
Hi.  I'm just trying out the new way to create a custom User class by extending the AbstractBaseUser class.  I essentially just copied the AbstractUser and UserManager classes from auth.models and customized the fields the way I want 'em.  I also set AUTH_USER_MODEL in settings appropriately.

But when I do syncdb, the tables get created fine, but when I try to create a superuser, it asks for the username twice, then throws this error

TypeError: create_superuser() got multiple values for keyword argument 'username'

Anyone know what's going on?

Chris Pagnutti

unread,
Oct 18, 2012, 7:50:38 PM10/18/12
to django...@googlegroups.com
Blarghh!  Ok, I'm serious that I spent considerable time Googling, poring over the contrib.auth and core files and otherwise staring at my screen to try to fix this on my own before posting.  But of course I figure it out two minutes after I wasted the time of anyone who actually read this post.

The problem was that I had
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['username','email','first_name'...]
in my user class.  Once I removed 'username' from the REQUIRED_FIELDS, it worked like a charm.

Lesson learned: Read the docs more carefully
"REQUIRED_FIELDS must contain all required fields on your User model, but should not contain theUSERNAME_FIELD."

Russell Keith-Magee

unread,
Oct 19, 2012, 12:36:01 AM10/19/12
to django...@googlegroups.com
On Fri, Oct 19, 2012 at 3:50 AM, Chris Pagnutti
<chris.p...@gmail.com> wrote:
> Blarghh! Ok, I'm serious that I spent considerable time Googling, poring
> over the contrib.auth and core files and otherwise staring at my screen to
> try to fix this on my own before posting. But of course I figure it out two
> minutes after I wasted the time of anyone who actually read this post.
>
> The problem was that I had
> USERNAME_FIELD = 'username'
> REQUIRED_FIELDS = ['username','email','first_name'...]
> in my user class. Once I removed 'username' from the REQUIRED_FIELDS, it
> worked like a charm.
>
> Lesson learned: Read the docs more carefully
> "REQUIRED_FIELDS must contain all required fields on your User model, but
> should not contain theUSERNAME_FIELD."

Always a good lesson to learn :-)

However, you raise a valid point. This is an error case that we should
be able to validate. It's easy to check "if USERNAME_FIELD in
REQUIRED_FIELDS", and your first experience shouldn't be an obscure
error message about duplicated data. I've raised ticket #19150 to
track this. Thanks for the report!

Yours,
Russ Magee %-)

Chris Pagnutti

unread,
Oct 19, 2012, 10:20:17 PM10/19/12
to django...@googlegroups.com
Right on.  Thanks Russ.


On Thursday, October 18, 2012 3:38:05 PM UTC-4, Chris Pagnutti wrote:
Reply all
Reply to author
Forward
0 new messages