[Django] #25555: Django swallows exceptions when running management commands

14 views
Skip to first unread message

Django

unread,
Oct 15, 2015, 3:44:09 AM10/15/15
to django-...@googlegroups.com
#25555: Django swallows exceptions when running management commands
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core | Version: 1.8
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
With Django 1.8.5 and after following steps in a fresh project:
1. Add settings.LOGGING = {'invalid'}
2. python manage.py 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.

Stacktrace:
{{{
(tehku2_env)securejava@debian:~/projects/testapp$ python manage.py
runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/core/management/__init__.py", line 351, in
execute_from_command_line
utility.execute()
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/core/management/__init__.py", line 343, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/core/management/__init__.py", line 177, in fetch_command
commands = get_commands()
File "/home/securejava/projects/tehku2_env/lib/python3.4/functools.py",
line 434, in wrapper
result = user_function(*args, **kwds)
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/core/management/__init__.py", 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/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/apps/registry.py", 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 manage.py --version, the exception isn't
swallowed.

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

Django

unread,
Oct 15, 2015, 8:11:27 AM10/15/15
to django-...@googlegroups.com
#25555: runserver swallows exceptions

-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* stage: Unreviewed => Accepted


Comment:

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

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

Django

unread,
Oct 15, 2015, 8:53:12 AM10/15/15
to django-...@googlegroups.com
#25555: runserver swallows exceptions

-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aaugustin):

This could be a duplicate of #25510. Anssi, can you test if
https://github.com/django/django/pull/5402 improves the situation?

--
Ticket URL: <https://code.djangoproject.com/ticket/25555#comment:2>

Django

unread,
Oct 15, 2015, 11:25:30 AM10/15/15
to django-...@googlegroups.com
#25555: runserver swallows exceptions

-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by akaariai):

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
models.py of some installed app, then I get the following exception:
{{{

(tehku2_env)securejava@debian:~/projects/tehku2$ python manage.py


runserver
Traceback (most recent call last):

File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/core/management/__init__.py", line 317, in execute
autoreload.check_errors(django.setup)()
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File
"/home/securejava/projects/tehku2_env/lib/python3.4/importlib/__init__.py",
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/models.py", line 114, in
<module>
raise Exception("hara")
Exception: hara

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "manage.py", line 9, in <module>


execute_from_command_line(sys.argv)
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/core/management/__init__.py", line 351, in
execute_from_command_line
utility.execute()
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-

packages/django/core/management/__init__.py", line 321, in execute
apps.populate([])
File "/home/securejava/projects/tehku2_env/lib/python3.4/site-
packages/django/apps/registry.py", line 78, in populate
raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant
}}}

I guess we want to avoid that.

--
Ticket URL: <https://code.djangoproject.com/ticket/25555#comment:3>

Django

unread,
Oct 15, 2015, 1:09:21 PM10/15/15
to django-...@googlegroups.com
#25555: runserver swallows exceptions

-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

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


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/25555#comment:4>

Django

unread,
Oct 15, 2015, 4:04:51 PM10/15/15
to django-...@googlegroups.com
#25555: runserver swallows exceptions

-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aaugustin):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/25555#comment:5>

Reply all
Reply to author
Forward
0 new messages