From d2ff8a7241b621b8013c7ec1631e95ae4445f76d Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 9 Dec 2014 08:43:40 -0500 Subject: [PATCH] Fixed #23975 -- Restored pre_migrate signal if all apps have migrations. Thanks kmmbvnr for the report. --- django/core/management/commands/migrate.py | 1 + docs/releases/1.7.2.txt | 3 +++ .../custom_migrations/__init__.py | 0 tests/migrate_signals/tests.py | 21 ++++++++++++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/migrate_signals/custom_migrations/__init__.py diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index 00732390aa..69ccbd3548 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -156,6 +156,7 @@ class Command(BaseCommand): created_models = self.sync_apps(connection, executor.loader.unmigrated_apps) else: created_models = [] + emit_pre_migrate_signal([], self.verbosity, self.interactive, connection.alias) # The test runner requires us to flush after a syncdb but before migrations, # so do that here. diff --git a/docs/releases/1.7.2.txt b/docs/releases/1.7.2.txt index dedf92c8cb..860c819525 100644 --- a/docs/releases/1.7.2.txt +++ b/docs/releases/1.7.2.txt @@ -146,3 +146,6 @@ Bugfixes * Fixed migration crash when adding ``order_with_respect_to`` to a table with existing rows (:ticket:`23983`). + +* Restored the ``pre_migrate`` signal if all apps have migrations + (:ticket:`23975`). diff --git a/tests/migrate_signals/custom_migrations/__init__.py b/tests/migrate_signals/custom_migrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/migrate_signals/tests.py b/tests/migrate_signals/tests.py index 883744b905..cacf39888c 100644 --- a/tests/migrate_signals/tests.py +++ b/tests/migrate_signals/tests.py @@ -1,7 +1,7 @@ from django.apps import apps from django.core import management from django.db.models import signals -from django.test import TestCase +from django.test import override_settings, TestCase from django.utils import six @@ -75,3 +75,22 @@ class MigrateSignalTests(TestCase): self.assertEqual(args['verbosity'], MIGRATE_VERBOSITY) self.assertEqual(args['interactive'], MIGRATE_INTERACTIVE) self.assertEqual(args['using'], 'default') + + @override_settings(MIGRATION_MODULES={'migrate_signals': 'migrate_signals.custom_migrations'}) + def test_pre_migrate_migrations_only(self): + """ + If all apps have migrations, pre_migrate should be sent. + """ + r = PreMigrateReceiver() + signals.pre_migrate.connect(r, sender=APP_CONFIG) + stdout = six.StringIO() + management.call_command('migrate', database=MIGRATE_DATABASE, + verbosity=MIGRATE_VERBOSITY, interactive=MIGRATE_INTERACTIVE, + load_initial_data=False, stdout=stdout) + args = r.call_args + self.assertEqual(r.call_counter, 1) + self.assertEqual(set(args), set(PRE_MIGRATE_ARGS)) + self.assertEqual(args['app_config'], APP_CONFIG) + self.assertEqual(args['verbosity'], MIGRATE_VERBOSITY) + self.assertEqual(args['interactive'], MIGRATE_INTERACTIVE) + self.assertEqual(args['using'], 'default')