[Django] #18845: Runtime error in setting.py causes silent exception and empty apps list

10 views
Skip to first unread message

Django

unread,
Aug 24, 2012, 12:54:22 AM8/24/12
to django-...@googlegroups.com
#18845: Runtime error in setting.py causes silent exception and empty apps list
-------------------------------------+-------------------------------------
Reporter: ac@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.4
commands) | Keywords: management installed
Severity: Normal | apps settings exception
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
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[[BR]]
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:[[BR]]
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

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

Django

unread,
Aug 24, 2012, 4:36:16 AM8/24/12
to django-...@googlegroups.com
#18845: Runtime error in setting.py causes silent exception and empty apps list
-------------------------------------+-------------------------------------
Reporter: ac@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage:
Keywords: management | Unreviewed
installed apps settings exception | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by claudep):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Can you give use an example of the type of error you had in your
settings.py to reproduce the issue?

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

Django

unread,
Aug 24, 2012, 11:52:33 AM8/24/12
to django-...@googlegroups.com
#18845: Runtime error in setting.py causes silent exception and empty apps list
-------------------------------------+-------------------------------------
Reporter: ac@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage:
Keywords: management | Unreviewed
installed apps settings exception | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

Replying to [comment:1 claudep]:

> Can you give use an example of the type of error you had in your
settings.py to reproduce the issue?

[[BR]]
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.

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

Django

unread,
Aug 24, 2012, 1:43:01 PM8/24/12
to django-...@googlegroups.com
#18845: Runtime error in setting.py causes silent exception and empty apps list
-------------------------------------+-------------------------------------
Reporter: ac@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: management | Needs documentation: 0
installed apps settings exception | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by claudep):

* easy: 1 => 0
* stage: Unreviewed => Accepted


Comment:

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.

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

Django

unread,
Aug 24, 2012, 3:04:03 PM8/24/12
to django-...@googlegroups.com
#18845: Runtime error in setting.py causes silent exception and empty apps list
-------------------------------------+-------------------------------------
Reporter: ac@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: management | Needs documentation: 0
installed apps settings exception | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by claudep):

* has_patch: 0 => 1


Comment:

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.

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

Django

unread,
Sep 26, 2012, 9:10:29 AM9/26/12
to django-...@googlegroups.com
#18845: Runtime error in setting.py causes silent exception and empty apps list
-------------------------------------+-------------------------------------
Reporter: ac@… | Owner: nobody
Type: Bug | Status: closed

Component: Core (Management | Version: 1.4
commands) | Resolution: fixed

Severity: Normal | Triage Stage: Accepted
Keywords: management | Needs documentation: 0
installed apps settings exception | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

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


Comment:

In [changeset:"bb7da7844ff9f11286509c22a2549bbd4553d58d"]:
{{{
#!CommitTicketReference repository=""
revision="bb7da7844ff9f11286509c22a2549bbd4553d58d"
Fixed #18845 -- Do not swallow AttributeErrors when running commands
}}}

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

Django

unread,
Feb 18, 2022, 2:02:25 PM2/18/22
to django-...@googlegroups.com
#18845: Runtime error in setting.py causes silent exception and empty apps list
-------------------------------------+-------------------------------------
Reporter: ac@… | Owner: nobody
Type: Bug | Status: closed

Component: Core (Management | Version: 1.4
commands) |
Severity: Normal | Resolution: fixed
Keywords: management | Triage Stage: Accepted
installed apps settings exception |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Anders Hovmöller):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/18845#comment:6>

Reply all
Reply to author
Forward
0 new messages