Fixed #27461 -- Fixed incorrect allow_migrate() arguments in makemigrations.
This commit is contained in:
parent
0d6c7cae7c
commit
373c6c409c
|
@ -105,7 +105,7 @@ class Command(BaseCommand):
|
|||
# At least one model must be migrated to the database.
|
||||
router.allow_migrate(connection.alias, app_label, model_name=model._meta.object_name)
|
||||
for app_label in consistency_check_labels
|
||||
for model in apps.get_models(app_label)
|
||||
for model in apps.get_app_config(app_label).get_models()
|
||||
)):
|
||||
loader.check_consistent_history(connection)
|
||||
|
||||
|
|
|
@ -12,3 +12,7 @@ Bugfixes
|
|||
* Quoted the Oracle test user's password in queries to fix the "ORA-00922:
|
||||
missing or invalid option" error when the password starts with a number or
|
||||
special character (:ticket:`27420`).
|
||||
|
||||
* Fixed incorrect ``app_label`` / ``model_name`` arguments for
|
||||
``allow_migrate()`` in ``makemigrations`` migration consistency checks
|
||||
(:ticket:`27461`).
|
||||
|
|
|
@ -598,6 +598,7 @@ class MakeMigrationsTests(MigrationTestBase):
|
|||
init_file = os.path.join(migration_dir, '__init__.py')
|
||||
self.assertTrue(os.path.exists(init_file))
|
||||
|
||||
@override_settings(INSTALLED_APPS=['migrations', 'migrations2'])
|
||||
def test_makemigrations_consistency_checks_respect_routers(self):
|
||||
"""
|
||||
The history consistency checks in makemigrations respect
|
||||
|
@ -638,7 +639,15 @@ class MakeMigrationsTests(MigrationTestBase):
|
|||
with self.settings(DATABASE_ROUTERS=['migrations.routers.TestRouter']):
|
||||
with mock.patch.object(TestRouter, 'allow_migrate', return_value=False) as allow_migrate:
|
||||
call_command('makemigrations', 'migrations', verbosity=0)
|
||||
allow_migrate.assert_called_with('other', 'migrations', model_name='UnicodeModel')
|
||||
allow_migrate.assert_any_call('other', 'migrations', model_name='UnicodeModel')
|
||||
# allow_migrate() is called with the correct arguments.
|
||||
self.assertGreater(len(allow_migrate.mock_calls), 0)
|
||||
for mock_call in allow_migrate.mock_calls:
|
||||
_, call_args, call_kwargs = mock_call
|
||||
connection_alias, app_name = call_args
|
||||
self.assertIn(connection_alias, ['default', 'other'])
|
||||
# Raises an error if invalid app_name/model_name occurs.
|
||||
apps.get_app_config(app_name).get_model(call_kwargs['model_name'])
|
||||
self.assertEqual(ensure_schema.call_count, 4)
|
||||
|
||||
def test_failing_migration(self):
|
||||
|
|
Loading…
Reference in New Issue