Code

#19049 closed Bug (fixed)

Subclassing AbstractUser doesn't work

Reported by: ivan_virabyan Owned by: nobody
Component: contrib.auth Version: master
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'.

Attachments (0)

Change History (9)

comment:1 Changed 19 months ago by akaariai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 19 months ago by ivan_virabyan

  • Resolution set to invalid
  • Status changed from new to closed

comment:3 Changed 19 months ago by ivan_virabyan

I'm sorry. I have misspelled setting name.

Last edited 19 months ago by ivan_virabyan (previous) (diff)

comment:4 Changed 19 months ago by ivan_virabyan

  • Resolution invalid deleted
  • Status changed from closed to reopened

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

Last edited 19 months ago by ivan_virabyan (previous) (diff)

comment:5 Changed 19 months ago by ptone

  • Triage Stage changed from Unreviewed to Accepted

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 Changed 19 months ago by russellm

  • Severity changed from Normal to Release 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 Changed 19 months ago by Russell Keith-Magee <russell@…>

  • Resolution set to fixed
  • Status changed from reopened to closed

In 3b6f980bedbbf091fe29bececa2b262d2084ce4d:

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

Thanks to Ivan Virabyan for the report.

comment:8 Changed 19 months ago by ptone

  • Resolution fixed deleted
  • Status changed from closed to reopened

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 Changed 19 months ago by Russell Keith-Magee <russell@…>

  • Resolution set to fixed
  • Status changed from reopened to closed

In 43530384b7f2a18b44e06e7043b988427b334653:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.