[Django] #29392: Command parsing does not handle options that conflict with `--settings`/`--pythonpath`

8 views
Skip to first unread message

Django

unread,
May 8, 2018, 1:56:05 PM5/8/18
to django-...@googlegroups.com
#29392: Command parsing does not handle options that conflict with
`--settings`/`--pythonpath`
-------------------------------------+-------------------------------------
Reporter: Ryan P | Owner: nobody
Kilby |
Type: Bug | Status: new
Component: Core | Version: 2.0
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
Argparse performs [https://docs.python.org/3/library/argparse.html
#argument-abbreviations-prefix-matching prefix matching] when arguments
are unambiguous (e.g., `--set=my.settings` and `--settings=my.settings`
are both valid). Since `--settings` and `--pythonpath` are
[https://github.com/django/django/blob/2.0/django/core/management/__init__.py#L306-L314
parsed before] the command is fetched, conflicting/ambiguous command
options are not checked. For example, if I have a command for
getting/setting config values, the result of using the `--set` option is:

{{{
$ python manage.py config --set foo bar
Traceback (most recent call last):
File "manage.py", line 20, in <module>
execute_from_command_line(sys.argv)
File ".venv/lib/python3.6/site-
packages/django/core/management/__init__.py", line 364, in
execute_from_command_line
utility.execute()
File ".venv/lib/python3.6/site-
packages/django/core/management/__init__.py", line 308, in execute
settings.INSTALLED_APPS
File ".venv/lib/python3.6/site-packages/django/conf/__init__.py", line
56, in __getattr__
self._setup(name)
File ".venv/lib/python3.6/site-packages/django/conf/__init__.py", line
41, in _setup
self._wrapped = Settings(settings_module)
File ".venv/lib/python3.6/site-packages/django/conf/__init__.py", line
110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File
"/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py",
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in
_find_and_load_unlocked
ModuleNotFoundError: No module named 'foo'
}}}

One solution would be to set
[https://docs.python.org/3/library/argparse.html#allow-abbrev
allow_abbrev] to `False`, which would disable prefix matching. However,
this option is only available in Python 3.5 and above. Also, this might be
considered a breaking change if users are expecting to be able to use the
abbreviated option names, but I don't know if that's really a concern.

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

Django

unread,
May 9, 2018, 3:22:26 AM5/9/18
to django-...@googlegroups.com
#29392: Command parsing does not handle options that conflict with
`--settings`/`--pythonpath`
-------------------------------------+-------------------------------------
Reporter: Ryan P Kilby | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* version: 2.0 => master
* type: Bug => New feature
* stage: Unreviewed => Accepted


Comment:

Hi Ryan. Thanks for the report. This seems reasonable.

Interestingly, with the patch, if you pass an abbreviation to second
parser you get the error you'd expect:

manage.py config: error: ambiguous option: --se could match --set,
--settings

> ...this option is only available in Python 3.5 and above.

Right. For that reason lets call this a New Feature and roll it into 2.1,
where we don't have to worry about compat. (This has existed for ≈forever
so I can't see the harm in holding off slightly.)

> Also, this might be considered a breaking change if users are expecting
to be able to use the abbreviated option names, but I don't know if that's
really a concern.

Yes, probably not a biggie but could you add a note to the Breaking
changes section in `2.1.txt`.

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

Django

unread,
May 14, 2018, 11:08:10 AM5/14/18
to django-...@googlegroups.com
#29392: Command parsing does not handle options that conflict with
`--settings`/`--pythonpath`
-------------------------------------+-------------------------------------
Reporter: Ryan P Kilby | Owner: lefcourn
Type: New feature | Status: assigned

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* owner: nobody => lefcourn
* status: new => assigned


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

Django

unread,
May 14, 2018, 11:33:38 AM5/14/18
to django-...@googlegroups.com
#29392: Command parsing does not handle options that conflict with
`--settings`/`--pythonpath`
-------------------------------------+-------------------------------------
Reporter: Ryan P Kilby | Owner: lefcourn
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

Comment (by Ryan P Kilby):

Thanks for the review Carlton. Added a note to the misc backwards
incompatibility section.

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

Django

unread,
May 14, 2018, 10:48:00 PM5/14/18
to django-...@googlegroups.com
#29392: Command parsing does not handle options that conflict with
`--settings`/`--pythonpath`
-------------------------------------+-------------------------------------
Reporter: Ryan P Kilby | Owner: lefcourn
Type: New feature | Status: closed

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"2dcc5d629a6439b5547cdd6e67815cabf608fcd4" 2dcc5d62]:
{{{
#!CommitTicketReference repository=""
revision="2dcc5d629a6439b5547cdd6e67815cabf608fcd4"
Fixed #29392 -- Disallowed use of abbreviated forms of --settings and
--pythonpath management command options.
}}}

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

Django

unread,
May 17, 2018, 1:13:32 PM5/17/18
to django-...@googlegroups.com
#29392: Command parsing does not handle options that conflict with
`--settings`/`--pythonpath`
-------------------------------------+-------------------------------------
Reporter: Ryan P Kilby | Owner: lefcourn
Type: New feature | Status: closed
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

Comment (by lefcourn):

Sorry, didn't realize that there was already a commit for this issue when
I assigned it to myself.

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

Reply all
Reply to author
Forward
0 new messages