[Django] #29328: Proxy for User model referenced as AUTH_USER_MODEL

4 views
Skip to first unread message

Django

unread,
Apr 15, 2018, 4:13:29 PM4/15/18
to django-...@googlegroups.com
#29328: Proxy for User model referenced as AUTH_USER_MODEL
------------------------------------------+-----------------------------
Reporter: nicolas-pantel | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 2.0
Severity: Normal | Keywords: model proxy
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+-----------------------------
As [https://docs.djangoproject.com/en/2.0/topics/auth/customizing
/#extending-the-existing-user-model stated in the doc], needing to add
some methods to User model, I tried to make a 'proxy' model.

settings.py:

{{{
AUTH_USER_MODEL = "myapp.MyMuser"
}}}

myapp/models.py:

{{{
from django.contrib.auth.models import User

class MyUser(User):
class Meta:
proxy = True
}}}

But on server launch, the following error is triggered:

{{{
Traceback (most recent call last):
File "./manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-
packages/django/core/management/__init__.py", line 363, in
execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-
packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line
27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py",
line 108, in populate
app_config.import_models()
File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py",
line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in
import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in
_call_with_frames_removed
File "/home/npantel/proxy_user/proxy_user/models.py", line 4, in
<module>
class MyUser(User):
File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py",
line 158, in __new__
raise TypeError("%s cannot proxy the swapped model '%s'." % (name,
base_meta.swapped))
TypeError: MyUser cannot proxy the swapped model 'proxy_user.MyUser'.
}}}

Is it a bug or a misunderstanding?

Thanks,
Nicolas Pantel

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

Django

unread,
Apr 15, 2018, 9:09:03 PM4/15/18
to django-...@googlegroups.com
#29328: Proxy for User model referenced as AUTH_USER_MODEL
--------------------------------+--------------------------------------
Reporter: nicolas-pantel | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.0
Severity: Normal | Resolution: invalid

Keywords: model proxy | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

[https://docs.djangoproject.com/en/dev/topics/auth/customizing/#custom-
users-and-proxy-models As documented], the behavior seems expected. Your
[https://groups.google.com/d/topic/django-users/FcJm7f12UIY/discussion
post on django-users], is the correct place to ask "is it a bug?"
questions (see TicketClosingReasons/UseSupportChannels).

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

Reply all
Reply to author
Forward
0 new messages