Opened 12 years ago

Closed 12 years ago

#19049 closed Bug (fixed)

Subclassing AbstractUser doesn't work

Reported by: Ivan Virabyan Owned by: nobody
Component: contrib.auth Version: dev
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

According to https://docs.djangoproject.com/en/dev/topics/auth/#extending-django-s-default-user I created my own User model

from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    avatar = models.ImageField(upload_to='avatars')

but django complains:

CommandError: One or more models did not validate:
accounts.user: Accessor for m2m field 'groups' clashes with related m2m field 'Group.user_set'. Add a related_name argument to the definition for 'groups'.
accounts.user: Accessor for m2m field 'user_permissions' clashes with related m2m field 'Permission.user_set'. Add a related_name argument to the definition for 'user_permissions'.
auth.user: Accessor for m2m field 'groups' clashes with related m2m field 'Group.user_set'. Add a related_name argument to the definition for 'groups'.
auth.user: Accessor for m2m field 'user_permissions' clashes with related m2m field 'Permission.user_set'. Add a related_name argument to the definition for 'user_permissions'.

Change History (9)

comment:1 by Anssi Kääriäinen, 12 years ago

Do you have settings.AUTH_USER_MODEL set to your User model? It seems you have both auth.user and accounts.user installed... I don't think it is possible to have subclassed AbstractUser in use in addition to the default User model.

comment:2 by Ivan Virabyan, 12 years ago

Resolution: invalid
Status: newclosed

comment:3 by Ivan Virabyan, 12 years ago

I'm sorry. I have misspelled setting name.

Last edited 12 years ago by Ivan Virabyan (previous) (diff)

comment:4 by Ivan Virabyan, 12 years ago

Resolution: invalid
Status: closedreopened

Nevertheless, django still complains. It only works if I rename my model to CustomUser or something.

Last edited 12 years ago by Ivan Virabyan (previous) (diff)

comment:5 by Preston Holmes, 12 years ago

Triage Stage: UnreviewedAccepted

this is because django.contrib.auth.models.User and group are being installed as loaded models, and reverse relations are being set to Django's default 'User' model, and reserving the user_set etc reverse relations

comment:6 by Russell Keith-Magee, 12 years ago

Severity: NormalRelease blocker

This will need to be fixed before release; banning "User" as a model name is a pretty big failing, and there's also the possibility that stray reverse relations are being installed.

comment:7 by Russell Keith-Magee <russell@…>, 12 years ago

Resolution: fixed
Status: reopenedclosed

In 3b6f980bedbbf091fe29bececa2b262d2084ce4d:

Fixed #19049 -- Ensure that swapped models aren't included in reverse field caches.

Thanks to Ivan Virabyan for the report.

comment:8 by Preston Holmes, 12 years ago

Resolution: fixed
Status: closedreopened

while this fixes the auth tests - it badly blows up everything else it seems

http://ci.djangoproject.com/job/Django/database=sqlite3,python=python2.7/1763/

comment:9 by Russell Keith-Magee <russell@…>, 12 years ago

Resolution: fixed
Status: reopenedclosed

In 43530384b7f2a18b44e06e7043b988427b334653:

Fixed #19049 -- Corrected dumb logic negation error from earlier patch.

Note: See TracTickets for help on using tickets.
Back to Top