[Django] #25285: Unknown command raise the wrong exception when no project exist

37 views
Skip to first unread message

Django

unread,
Aug 18, 2015, 5:39:33 AM8/18/15
to django-...@googlegroups.com
#25285: Unknown command raise the wrong exception when no project exist
--------------------------------------------+------------------------------
Reporter: mlorant | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Management commands) | Version: master
Severity: Normal | Keywords: django-admin
| command
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 1 | UI/UX: 0
--------------------------------------------+------------------------------
When you try to execute a command that does not exist outside a Django
project (e.g. createproject instead of startproject...), Django raise a
`ImproperlyConfigured` that does not fit with the real error:


{{{
(testdjango):~/testdjango$ django-admin.py not-a-real-command test
Traceback (most recent call last):
File "/root/testdjango/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/root/testdjango/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 338, in
execute_from_command_line
utility.execute()
File "/root/testdjango/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/root/testdjango/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 182, in fetch_command
settings.INSTALLED_APPS
File "/root/testdjango/local/lib/python2.7/site-
packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/root/testdjango/local/lib/python2.7/site-
packages/django/conf/__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting
INSTALLED_APPS, but settings are not configured. You must either define
the environment variable DJANGO_SETTINGS_MODULE or call
settings.configure() before accessing settings.
}}}

The expected output is:

{{{
(testdjango):~/testdjango$ django-admin.py not-a-real-command test
Unknown command: 'not-a-real-command'
Type 'django-admin.py help' for usage.
}}}

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

Django

unread,
Aug 18, 2015, 5:39:51 AM8/18/15
to django-...@googlegroups.com
#25285: Unknown command raise the wrong exception when no project exist
----------------------------------------+----------------------------

Reporter: mlorant | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Management commands) | Version: master
Severity: Normal | Resolution:

Keywords: django-admin command | Triage Stage: Unreviewed
Has patch: 1 | Easy pickings: 1
UI/UX: 0 |
----------------------------------------+----------------------------
Changes (by mlorant):

* Attachment "unknown-command-exception.patch" added.

Suggestion of patch

Django

unread,
Aug 18, 2015, 8:31:27 PM8/18/15
to django-...@googlegroups.com
#25285: Unknown django-admin command raises "settings not configured" when no
project exists
-------------------------------------+-------------------------------------
Reporter: mlorant | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: django-admin | Triage Stage: Accepted
command |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* easy: 1 => 0
* needs_docs: => 0
* stage: Unreviewed => Accepted


Comment:

I think your proposal makes sense. It keeps the fix for #21634, but only
when using `manage.py`. Claude, what do you think?

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

Django

unread,
Aug 19, 2015, 6:02:33 AM8/19/15
to django-...@googlegroups.com
#25285: Unknown django-admin command raises "settings not configured" when no
project exists
-------------------------------------+-------------------------------------
Reporter: mlorant | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: django-admin | Triage Stage: Accepted
command |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by claudep):

Here is my suggestion: https://github.com/django/django/pull/5158

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

Django

unread,
Aug 19, 2015, 6:08:02 AM8/19/15
to django-...@googlegroups.com
#25285: Unknown django-admin command raises "settings not configured" when no
project exists
-------------------------------------+-------------------------------------
Reporter: mlorant | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: django-admin | Triage Stage: Accepted
command |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by mlorant):

Indeed, as a Django user, I would also prefer this implementation: it
provides the correct error message and give a hint in case the user tried
to use a custom command. (Also, it avoids hardcoded filename, like
"django-admin" in the code...)

Thanks Claude.

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

Django

unread,
Aug 19, 2015, 11:25:10 AM8/19/15
to django-...@googlegroups.com
#25285: Unknown django-admin command raises "settings not configured" when no
project exists
-------------------------------------+-------------------------------------
Reporter: mlorant | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: django-admin | Triage Stage: Ready for
command | checkin

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

* stage: Accepted => Ready for checkin


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

Django

unread,
Aug 19, 2015, 1:59:52 PM8/19/15
to django-...@googlegroups.com
#25285: Unknown django-admin command raises "settings not configured" when no
project exists
-------------------------------------+-------------------------------------
Reporter: mlorant | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution: fixed

Keywords: django-admin | Triage Stage: Ready for
command | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

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


Comment:

In [changeset:"c1893e2839245e75b35597a9200d9ef9c1ad9b46" c1893e2]:
{{{
#!CommitTicketReference repository=""
revision="c1893e2839245e75b35597a9200d9ef9c1ad9b46"
Fixed #25285 -- Provided unknown command message with plain django-
admin.py

Thanks Maxime Lorant for the report and Tim Graham for suggesting
the improved comment.
}}}

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

Reply all
Reply to author
Forward
0 new messages