Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#21715 closed Bug (fixed)

Cannot run tests with the new changes on @master anymore

Reported by: Matthias Kestenholz Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I tried running the of Towel (https://github.com/matthiask/towel/) with Django@master this morning. It does not really matter which project I'm taking though, none of them work right now.

For reference, the initial traceback:

mk@mbp:~/Projects/towel/tests$ .tox/py32-django17/bin/python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 13, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/core/management/__init__.py", line 287, in fetch_command
    commands = get_commands()
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/core/management/__init__.py", line 124, in get_commands
    apps.populate(installed_apps)
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/apps/registry.py", line 87, in populate
    app_config.import_models(all_models)
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/apps/base.py", line 160, in import_models
    self.models_module = import_module(models_module_name)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/__init__.py", line 124, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 821, in _gcd_import
    loader.load_module(name)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 436, in load_module
    return self._load_module(fullname)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 141, in decorated
    return fxn(self, module, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 342, in _load_module
    exec(code_object, module.__dict__)
  File "/Users/mk/Projects/towel/tests/testapp/models.py", line 9, in <module>
    from towel.modelview import ModelViewURLs
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 436, in load_module
    return self._load_module(fullname)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 141, in decorated
    return fxn(self, module, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 342, in _load_module
    exec(code_object, module.__dict__)
  File "/Users/mk/Projects/towel/towel/modelview.py", line 24, in <module>
    class ModelView(object):
  File "/Users/mk/Projects/towel/towel/modelview.py", line 98, in ModelView
    _('The new object has been successfully created.')),
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/utils/translation/__init__.py", line 80, in ugettext
    return _trans.ugettext(message)
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/utils/translation/trans_real.py", line 310, in gettext
    return do_translate(message, 'gettext')
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/utils/translation/trans_real.py", line 297, in do_translate
    _default = translation(settings.LANGUAGE_CODE)
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/utils/translation/trans_real.py", line 199, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/utils/translation/trans_real.py", line 182, in _fetch
    for app_config in reversed(list(apps.get_app_configs())):
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/apps/registry.py", line 108, in get_app_configs
    self.check_ready()
  File "/Users/mk/Projects/towel/tests/.tox/py32-django17/src/django/django/apps/registry.py", line 101, in check_ready
    "App registry isn't populated yet. "
RuntimeError: App registry isn't populated yet. Have you called django.setup()?

I could not get it running after several attempts of adding django.setup() to various places in manage.py and django/core/management/base.py

The code always hits populate(), ugettext(), get_app_configs(), check_ready, only the first few lines of the traceback are different.

Change History (7)

comment:1 by Marc Tamlyn, 11 years ago

I think you can fix this by using ugettext_lazy in place of ugettext which is certainly advisable for module-level code.

comment:2 by Matthias Kestenholz, 11 years ago

Resolution: fixed
Status: newclosed

Thanks. I was obviously looking in the wrong direction. You also found a bug in my code. Sorry for the noise!

comment:3 by Marc Tamlyn, 11 years ago

Hmm, well the error message could be improved. For example I know that django.setup() is called by manage.py but you don't, and it wasn't obvious from the message that this was the issue.

comment:4 by Aymeric Augustin, 11 years ago

It's a purposeful side-effect of the recent app-loading changes that revealed a bug in your code -- it's always wrong to call ugettext at import time.

That said, at the very least, we need to improve the error message. I suspect this exception is going to be encountered often. In practice it happens as soon as importing modules triggers a call to the app registry. Not using lazy translations will be the most common culprit, but looking up templates would have the same effect.

Version 0, edited 11 years ago by Aymeric Augustin (next)

comment:5 by Aymeric Augustin, 11 years ago

Resolution: fixed
Status: closednew

comment:6 by Aymeric Augustin <aymeric.augustin@…>, 11 years ago

Resolution: fixed
Status: newclosed

In f46603f8304a5b39c3b3064ec819587a78937113:

Fleshed out release notes for app loading.

Fixed #21715.

comment:7 by Matthias Kestenholz, 11 years ago

Thanks, this is very helpful!

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