Fixed #29518 -- Added validation for sqlmigrate's app_label argument.
This commit is contained in:
parent
e7185a6514
commit
6b3e17bab6
1
AUTHORS
1
AUTHORS
|
@ -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>
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue