mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Refs #29506 -- Added validation for squashmigrations' app_label option.
This commit is contained in:
		| @@ -1,3 +1,4 @@ | |||||||
|  | from django.apps import apps | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
| from django.core.management.base import BaseCommand, CommandError | from django.core.management.base import BaseCommand, CommandError | ||||||
| from django.db import DEFAULT_DB_ALIAS, connections, migrations | from django.db import DEFAULT_DB_ALIAS, connections, migrations | ||||||
| @@ -46,7 +47,11 @@ class Command(BaseCommand): | |||||||
|         migration_name = options['migration_name'] |         migration_name = options['migration_name'] | ||||||
|         no_optimize = options['no_optimize'] |         no_optimize = options['no_optimize'] | ||||||
|         squashed_name = options['squashed_name'] |         squashed_name = options['squashed_name'] | ||||||
|  |         # Validate app_label. | ||||||
|  |         try: | ||||||
|  |             apps.get_app_config(app_label) | ||||||
|  |         except LookupError as err: | ||||||
|  |             raise CommandError(str(err)) | ||||||
|         # Load the current graph state, check the app and migration they asked for exists |         # Load the current graph state, check the app and migration they asked for exists | ||||||
|         loader = MigrationLoader(connections[DEFAULT_DB_ALIAS]) |         loader = MigrationLoader(connections[DEFAULT_DB_ALIAS]) | ||||||
|         if app_label not in loader.migrated_apps: |         if app_label not in loader.migrated_apps: | ||||||
|   | |||||||
| @@ -1433,3 +1433,11 @@ class AppLabelErrorTests(TestCase): | |||||||
|     def test_migrate_app_name_specified_as_label(self): |     def test_migrate_app_name_specified_as_label(self): | ||||||
|         with self.assertRaisesMessage(CommandError, self.did_you_mean_auth_error): |         with self.assertRaisesMessage(CommandError, self.did_you_mean_auth_error): | ||||||
|             call_command('migrate', 'django.contrib.auth') |             call_command('migrate', 'django.contrib.auth') | ||||||
|  |  | ||||||
|  |     def test_squashmigrations_nonexistent_app_label(self): | ||||||
|  |         with self.assertRaisesMessage(CommandError, self.nonexistent_app_error): | ||||||
|  |             call_command('squashmigrations', 'nonexistent_app', '0002') | ||||||
|  |  | ||||||
|  |     def test_squashmigrations_app_name_specified_as_label(self): | ||||||
|  |         with self.assertRaisesMessage(CommandError, self.did_you_mean_auth_error): | ||||||
|  |             call_command('squashmigrations', 'django.contrib.auth', '0002') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user