#22872: Backwards incompatible change: Can't proxy User model: RuntimeError: App
registry isn't ready yet.
-------------------------------+------------------------
     Reporter:  jdufresne      |      Owner:  nobody
         Type:  Bug            |     Status:  new
    Component:  Uncategorized  |    Version:  1.7-beta-2
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+------------------------
 My application creates proxies of the user model to add custom methods
 that are useful in certain contexts. There is an attempt to do this in a
 `AUTH_USER_MODEL` agnostic way. This fails with the latest beta version of
 1.7.

 Starting from a fresh install and project I created the following files in
 directory `myapp`.

 `myapp/models.py`

 {{{
 from django.contrib.auth import get_user_model


 class MyUser(get_user_model()):
     def my_method(self):
         return 'foo'

     class Meta:
         proxy = True
 }}}

 `myapp/tests.py`

 {{{
 from django.test import TestCase
 from myapp.models import MyUser


 class MyTestCase(TestCase):
     def test_my_user(self):
         user = MyUser()
         self.assertTrue(user)
 }}}


 Django 1.7 beta 2
 {{{
 $ python manage.py test
 Traceback (most recent call last):
   File "manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File "/home/jon/djtest/venv/lib/python2.7/site-
 packages/django/core/management/__init__.py", line 427, in
 execute_from_command_line
     utility.execute()
   File "/home/jon/djtest/venv/lib/python2.7/site-
 packages/django/core/management/__init__.py", line 391, in execute
     django.setup()
   File "/home/jon/djtest/venv/lib/python2.7/site-
 packages/django/__init__.py", line 21, in setup
     apps.populate(settings.INSTALLED_APPS)
   File "/home/jon/djtest/venv/lib/python2.7/site-
 packages/django/apps/registry.py", line 106, in populate
     app_config.import_models(all_models)
   File "/home/jon/djtest/venv/lib/python2.7/site-
 packages/django/apps/config.py", line 190, in import_models
     self.models_module = import_module(models_module_name)
   File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in
 import_module
     __import__(name)
   File "/home/jon/djtest/djtest/myapp/models.py", line 4, in <module>
     class MyUser(get_user_model()):
   File "/home/jon/djtest/venv/lib/python2.7/site-
 packages/django/contrib/auth/__init__.py", line 136, in get_user_model
     return django_apps.get_model(settings.AUTH_USER_MODEL)
   File "/home/jon/djtest/venv/lib/python2.7/site-
 packages/django/apps/registry.py", line 187, in get_model
     self.check_ready()
   File "/home/jon/djtest/venv/lib/python2.7/site-
 packages/django/apps/registry.py", line 119, in check_ready
     raise RuntimeError("App registry isn't ready yet.")
 RuntimeError: App registry isn't ready yet.
 }}}

 Django 1.6.5

 {{{
 $ python manage.py test
 Creating test database for alias 'default'...
 .
 ----------------------------------------------------------------------
 Ran 1 test in 0.001s

 OK
 Destroying test database for alias 'default'...
 }}}

 If there is a better (or forward compatible) way proxy an unknown `User`
 model, I'd be happy to hear about it.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22872>
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/052.80054077f63b26fb1181d3f78794f926%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to