Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25555 closed Cleanup/optimization (duplicate)

runserver swallows exceptions

Reported by: Anssi Kääriäinen Owned by: nobody
Component: Core (Management commands) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


With Django 1.8.5 and after following steps in a fresh project:

  1. Add settings.LOGGING = {'invalid'}
  2. python runserver

You'll get an exception mentioning that apps aren't ready yet. If you call django.setup() in a manual script you'll get a nice exception by which it is possible to see that your logging config is invalid.

The problem lies somewhere in the management command setup, or in the way get_app_configs() reports errors.


(tehku2_env)securejava@debian:~/projects/testapp$ python runserver
Traceback (most recent call last):
  File "", line 10, in <module>
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/core/management/", line 351, in execute_from_command_line
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/core/management/", line 343, in execute
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/core/management/", line 177, in fetch_command
    commands = get_commands()
  File "/home/securejava/projects/tehku2_env/lib/python3.4/", line 434, in wrapper
    result = user_function(*args, **kwds)
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/core/management/", line 72, in get_commands
    for app_config in reversed(list(apps.get_app_configs())):
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/apps/", line 137, in get_app_configs
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/apps/", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Interestingly if you run instead --version, the exception isn't swallowed.

Change History (5)

comment:1 by Claude Paroz, 9 years ago

Summary: Django swallows exceptions when running management commandsrunserver swallows exceptions
Triage Stage: UnreviewedAccepted

This is due to runserver being special-cased from cc14d51ee8325c82665cb98af4dfe49aab565d52 / #24704 (sorry Aymeric!)

comment:2 by Aymeric Augustin, 9 years ago

This could be a duplicate of #25510. Anssi, can you test if improves the situation?

comment:3 by Anssi Kääriäinen, 9 years ago

Yes, that one fixes the issue. Instead of getting apps not ready exception, I can see the original exception on command line. If I fix the error in the settings, the project is correctly reloaded.

If I start the runserver with an exception caused by a mistake in of some installed app, then I get the following exception:

(tehku2_env)securejava@debian:~/projects/tehku2$ python runserver
Traceback (most recent call last):
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/core/management/", line 317, in execute
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/utils/", line 229, in wrapper
    fn(*args, **kwargs)
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/", line 18, in setup
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/apps/", line 108, in populate
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/apps/", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/securejava/projects/tehku2_env/lib/python3.4/importlib/", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/securejava/projects/tehku2/tehku/", line 114, in <module>
    raise Exception("hara")
Exception: hara

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 9, in <module>
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/core/management/", line 351, in execute_from_command_line
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/core/management/", line 321, in execute
  File "/home/securejava/projects/tehku2_env/lib/python3.4/site-packages/django/apps/", line 78, in populate
    raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant

I guess we want to avoid that.

comment:4 by Tim Graham, 9 years ago

Resolution: duplicate
Status: newclosed

I left the same comment about avoiding RuntimeError: populate() isn't reentrant on the pull request.

comment:5 by Aymeric Augustin, 9 years ago

I'm closing this ticket since it appears identical to #25510. FYI I updated the PR.

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