﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22872	Backwards incompatible change: Can't proxy User model: RuntimeError: App registry isn't ready yet.	Jon Dufresne	nobody	"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."	Cleanup/optimization	closed	Documentation	1.7	Normal	wontfix		app-loading	Accepted	0	0	0	0	0	0
