#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.48bf9b12baaf2b9ead8ef5b9dea13cbf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.