summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan P Kilby <rpkilby@ncsu.edu>2018-05-08 14:50:35 -0400
committerTim Graham <timograham@gmail.com>2018-05-14 22:18:22 -0400
commit2dcc5d629a6439b5547cdd6e67815cabf608fcd4 (patch)
tree888271928a4a7d53dbcbe956d96dd1de4a35ea2e
parent265506bbc347a6b3fcc6c66ab1a2417b3b7ea57a (diff)
Fixed #29392 -- Disallowed use of abbreviated forms of --settings and --pythonpath management command options.
-rw-r--r--django/core/management/__init__.py2
-rw-r--r--docs/releases/2.1.txt3
-rw-r--r--tests/user_commands/management/commands/set_option.py10
-rw-r--r--tests/user_commands/tests.py10
4 files changed, 24 insertions, 1 deletions
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index 8d39b86472..bffa3d666a 100644
--- a/django/core/management/__init__.py
+++ b/django/core/management/__init__.py
@@ -311,7 +311,7 @@ class ManagementUtility:
# Preprocess options to extract --settings and --pythonpath.
# These options could affect the commands that are available, so they
# must be processed early.
- parser = CommandParser(usage='%(prog)s subcommand [options] [args]', add_help=False)
+ parser = CommandParser(usage='%(prog)s subcommand [options] [args]', add_help=False, allow_abbrev=False)
parser.add_argument('--settings')
parser.add_argument('--pythonpath')
parser.add_argument('args', nargs='*') # catch-all
diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt
index 26911c4481..bc565d51b1 100644
--- a/docs/releases/2.1.txt
+++ b/docs/releases/2.1.txt
@@ -423,6 +423,9 @@ Miscellaneous
to insert untranslated content into the database), use the new
:ref:`@no_translations decorator <management-commands-and-locales>`.
+* Management commands no longer allow the abbreviated forms of the
+ ``--settings`` and ``--pythonpath`` arguments.
+
.. _deprecated-features-2.1:
Features deprecated in 2.1
diff --git a/tests/user_commands/management/commands/set_option.py b/tests/user_commands/management/commands/set_option.py
new file mode 100644
index 0000000000..a6e3c9bb6a
--- /dev/null
+++ b/tests/user_commands/management/commands/set_option.py
@@ -0,0 +1,10 @@
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+
+ def add_arguments(self, parser):
+ parser.add_argument('--set')
+
+ def handle(self, **options):
+ self.stdout.write('Set %s' % options['set'])
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py
index b5d29721b4..92263f58d6 100644
--- a/tests/user_commands/tests.py
+++ b/tests/user_commands/tests.py
@@ -232,6 +232,16 @@ class CommandRunTests(AdminScriptTestCase):
self.assertNoOutput(err)
self.assertEqual(out.strip(), '/PREFIX/some/url/')
+ def test_disallowed_abbreviated_options(self):
+ """
+ To avoid conflicts with custom options, commands don't allow
+ abbreviated forms of the --setting and --pythonpath options.
+ """
+ self.write_settings('settings.py', apps=['user_commands'])
+ out, err = self.run_manage(['set_option', '--set', 'foo'])
+ self.assertNoOutput(err)
+ self.assertEqual(out.strip(), 'Set foo')
+
class UtilsTests(SimpleTestCase):