#18845 closed Bug (fixed)
Runtime error in setting.py causes silent exception and empty apps list
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.4 |
Severity: | Normal | Keywords: | management installed apps settings exception |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I had a runtime error in my settings.py file that wasn't being reported.
django/config/init.py : 94 was silently re-throwing, and
django/core/management/init.py : 103 was setting the INSTALLED_APPS list to an empty array.
I suggest the following changes:
django/config/init.py : 94 : except Exception, e:
django/core/management/init.py : 103 : sys.stdout.write('%s\n' % e)
This will result in the following printed on execution of any management command:
Could not import settings '<project>.settings' (Is it on sys.path?): <exception description here>
Thank you
Attachments (1)
Change History (7)
follow-up: 2 comment:1 by , 12 years ago
comment:2 by , 12 years ago
Replying to claudep:
Can you give use an example of the type of error you had in your settings.py to reproduce the issue?
Sure. I am putting a class Config in settings.py, containing various debug switches that I'm using further down in settings.py. My mistake was to refer to a class variable of Config that I forgot to set.
# settings.py class Config: pass A = Config.B
Whilst runserver
fails with the correct AttributeError: class Config has no attribute 'B'
collectstatic
fails silently/misleadingly with Unknown command: 'collectstatic'
Whilst it's true that had I simply run runserver
I would have found the error (facedesk), it should be reported for all manage.py
commands.
comment:3 by , 12 years ago
Easy pickings: | unset |
---|---|
Triage Stage: | Unreviewed → Accepted |
Agreed that in your case, the exception should not be swallowed. Now the fix is not so trivial, because you have to take into account the case of the startproject
command where accessing settings.INSTALLED_APPS will fail and we should not propagate the error in that case.
comment:4 by , 12 years ago
Has patch: | set |
---|
I do not know why get_commands()
was swallowing AttributeError/EnvironmentError. Neither source code or commit provide any clue. So I suggest to only catch ImportError there.
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:6 by , 3 years ago
This bug is not fixed. I'm not totally sure how to actually trigger it though, but I'm trying to help someone with this issue and it's not going well!
There's a bunch of people with this problem too: https://stackoverflow.com/questions/17804743/django-admin-py-unknown-command-collectstatic
I can fake trigger this by adding import foo
inside ManagementUtility.execute
:
try: import foo settings.INSTALLED_APPS except ImproperlyConfigured as exc: self.settings_exception = exc except ImportError as exc: self.settings_exception = exc
Now I get the silent failure.
Can you give use an example of the type of error you had in your settings.py to reproduce the issue?