Fixed #21015 -- Fixed MigrationLoader when importlib.import_module returns a file module or an empty directory.
This commit is contained in:
parent
82bbb9fe81
commit
e1266e50b2
|
@ -64,6 +64,13 @@ class MigrationLoader(object):
|
||||||
self.unmigrated_apps.add(app_label)
|
self.unmigrated_apps.add(app_label)
|
||||||
continue
|
continue
|
||||||
raise
|
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)
|
self.migrated_apps.add(app_label)
|
||||||
directory = os.path.dirname(module.__file__)
|
directory = os.path.dirname(module.__file__)
|
||||||
# Scan for .py[c|o] files
|
# Scan for .py[c|o] files
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
from unittest import skipIf
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db.migrations.loader import MigrationLoader, AmbiguityError
|
from django.db.migrations.loader import MigrationLoader, AmbiguityError
|
||||||
from django.db.migrations.recorder import MigrationRecorder
|
from django.db.migrations.recorder import MigrationRecorder
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
class RecorderTests(TestCase):
|
class RecorderTests(TestCase):
|
||||||
|
@ -84,3 +87,16 @@ class LoaderTests(TestCase):
|
||||||
with override_settings(MIGRATION_MODULES={"migrations": "migrations.faulty_migrations.import_error"}):
|
with override_settings(MIGRATION_MODULES={"migrations": "migrations.faulty_migrations.import_error"}):
|
||||||
with self.assertRaises(ImportError):
|
with self.assertRaises(ImportError):
|
||||||
migration_loader.load_disk()
|
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()
|
||||||
|
|
Loading…
Reference in New Issue