From 373c6c409c310cb61e1e9c9aff4adba379ffd0b4 Mon Sep 17 00:00:00 2001 From: Joseph Kahn Date: Wed, 9 Nov 2016 10:27:19 -0500 Subject: [PATCH] Fixed #27461 -- Fixed incorrect allow_migrate() arguments in makemigrations. --- django/core/management/commands/makemigrations.py | 2 +- docs/releases/1.10.4.txt | 4 ++++ tests/migrations/test_commands.py | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py index 0b39536f5b..e648880ef0 100644 --- a/django/core/management/commands/makemigrations.py +++ b/django/core/management/commands/makemigrations.py @@ -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) diff --git a/docs/releases/1.10.4.txt b/docs/releases/1.10.4.txt index c9c6181beb..3304df9071 100644 --- a/docs/releases/1.10.4.txt +++ b/docs/releases/1.10.4.txt @@ -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`). diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index fb2b0fb877..e138ef40bf 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -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):