From 82bbb9fe812ac2a575bf1291055093adfb9b8fff Mon Sep 17 00:00:00 2001 From: Loic Bistuer Date: Fri, 6 Sep 2013 03:51:11 +0700 Subject: [PATCH] Fixed #21014 -- Fixed gobbled ImportError in MigrationLoader. --- django/db/migrations/loader.py | 1 + .../migrations/faulty_migrations/import_error/__init__.py | 1 + tests/migrations/test_loader.py | 7 +++++++ 3 files changed, 9 insertions(+) create mode 100644 tests/migrations/faulty_migrations/import_error/__init__.py diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py index 6ad6959787..f3617764ef 100644 --- a/django/db/migrations/loader.py +++ b/django/db/migrations/loader.py @@ -63,6 +63,7 @@ class MigrationLoader(object): if "No module named" in str(e) and "migrations" in str(e): self.unmigrated_apps.add(app_label) continue + raise self.migrated_apps.add(app_label) directory = os.path.dirname(module.__file__) # Scan for .py[c|o] files diff --git a/tests/migrations/faulty_migrations/import_error/__init__.py b/tests/migrations/faulty_migrations/import_error/__init__.py new file mode 100644 index 0000000000..616c209dad --- /dev/null +++ b/tests/migrations/faulty_migrations/import_error/__init__.py @@ -0,0 +1 @@ +import fake_python_module diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py index b9ad9726ae..6810089603 100644 --- a/tests/migrations/test_loader.py +++ b/tests/migrations/test_loader.py @@ -77,3 +77,10 @@ class LoaderTests(TestCase): migration_loader.get_migration_by_prefix("migrations", "0") with self.assertRaises(KeyError): migration_loader.get_migration_by_prefix("migrations", "blarg") + + def test_load_import_error(self): + migration_loader = MigrationLoader(connection) + + with override_settings(MIGRATION_MODULES={"migrations": "migrations.faulty_migrations.import_error"}): + with self.assertRaises(ImportError): + migration_loader.load_disk()