diff options
| author | oliver <myungsekyo@gmail.com> | 2018-06-25 23:43:12 +0900 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-06-25 10:43:12 -0400 |
| commit | 6b3e17bab61b94a307d5b276480f8a0e125cb2e5 (patch) | |
| tree | dd43b6e11b7fcfb9d293723410539719a0b1f719 | |
| parent | e7185a6514ee83802f07ca1f6d2dff615b8fdfed (diff) | |
Fixed #29518 -- Added validation for sqlmigrate's app_label argument.
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | django/core/management/commands/sqlmigrate.py | 6 | ||||
| -rw-r--r-- | tests/migrations/test_commands.py | 8 |
3 files changed, 15 insertions, 0 deletions
@@ -739,6 +739,7 @@ answer newbie questions, and generally made Django that much better: Sean Brant Sebastian Hillig <sebastian.hillig@gmail.com> Sebastian Spiegel <http://www.tivix.com/> + Segyo Myung <myungsekyo@gmail.com> Selwin Ong <selwin@ui.co.id> Sengtha Chay <sengtha@e-khmer.com> Senko Rašić <senko.rasic@dobarkod.hr> diff --git a/django/core/management/commands/sqlmigrate.py b/django/core/management/commands/sqlmigrate.py index 4d0b08b175..32a78da452 100644 --- a/django/core/management/commands/sqlmigrate.py +++ b/django/core/management/commands/sqlmigrate.py @@ -1,3 +1,4 @@ +from django.apps import apps from django.core.management.base import BaseCommand, CommandError from django.db import DEFAULT_DB_ALIAS, connections from django.db.migrations.executor import MigrationExecutor @@ -37,6 +38,11 @@ class Command(BaseCommand): # Resolve command-line arguments into a migration app_label, migration_name = options['app_label'], options['migration_name'] + # Validate app_label + try: + apps.get_app_config(app_label) + except LookupError as err: + raise CommandError(str(err)) if app_label not in executor.loader.migrated_apps: raise CommandError("App '%s' does not have migrations" % app_label) try: diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 4f01a3b665..f625a47c7f 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -1434,6 +1434,14 @@ class AppLabelErrorTests(TestCase): with self.assertRaisesMessage(CommandError, self.did_you_mean_auth_error): call_command('migrate', 'django.contrib.auth') + def test_sqlmigrate_nonexistent_app_label(self): + with self.assertRaisesMessage(CommandError, self.nonexistent_app_error): + call_command('sqlmigrate', 'nonexistent_app', '0002') + + def test_sqlmigrate_app_name_specified_as_label(self): + with self.assertRaisesMessage(CommandError, self.did_you_mean_auth_error): + call_command('sqlmigrate', 'django.contrib.auth', '0002') + def test_squashmigrations_nonexistent_app_label(self): with self.assertRaisesMessage(CommandError, self.nonexistent_app_error): call_command('squashmigrations', 'nonexistent_app', '0002') |
