Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #21015 -- Fixed MigrationLoader when importlib.import_module re…

…turns a file module or an empty directory.
  • Loading branch information...
commit e1266e50b29540c07a78ab6f544d9a5073ee8a58 1 parent 82bbb9f
@loic loic authored timgraham committed
View
7 django/db/migrations/loader.py
@@ -64,6 +64,13 @@ def load_disk(self):
self.unmigrated_apps.add(app_label)
continue
raise
+ else:
+ # PY3 will happily import empty dirs as namespaces.
+ if not hasattr(module, '__file__'):
+ continue
+ # Module is not a package (e.g. migrations.py).
+ if not hasattr(module, '__path__'):
+ continue
self.migrated_apps.add(app_label)
directory = os.path.dirname(module.__file__)
# Scan for .py[c|o] files
View
0  tests/migrations/faulty_migrations/__init__.py
No changes.
View
0  tests/migrations/faulty_migrations/file.py
No changes.
View
0  tests/migrations/faulty_migrations/namespace/foo/__init__.py
No changes.
View
16 tests/migrations/test_loader.py
@@ -1,8 +1,11 @@
+from unittest import skipIf
+
from django.test import TestCase
from django.test.utils import override_settings
from django.db import connection
from django.db.migrations.loader import MigrationLoader, AmbiguityError
from django.db.migrations.recorder import MigrationRecorder
+from django.utils import six
class RecorderTests(TestCase):
@@ -84,3 +87,16 @@ def test_load_import_error(self):
with override_settings(MIGRATION_MODULES={"migrations": "migrations.faulty_migrations.import_error"}):
with self.assertRaises(ImportError):
migration_loader.load_disk()
+
+ def test_load_module_file(self):
+ migration_loader = MigrationLoader(connection)
+
+ with override_settings(MIGRATION_MODULES={"migrations": "migrations.faulty_migrations.file"}):
+ migration_loader.load_disk()
+
+ @skipIf(six.PY2, "PY2 doesn't load empty dirs.")
+ def test_load_empty_dir(self):
+ migration_loader = MigrationLoader(connection)
+
+ with override_settings(MIGRATION_MODULES={"migrations": "migrations.faulty_migrations.namespace"}):
+ migration_loader.load_disk()
Please sign in to comment.
Something went wrong with that request. Please try again.