Reverted "Fixed #30300 -- Allowed migrations to be loaded from directories without __init__.py file."
This reverts commit 3cd3bebe89
.
This commit is contained in:
parent
3f2821af6b
commit
ff55adbd0d
|
@ -88,6 +88,11 @@ class MigrationLoader:
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
|
# Empty directories are namespaces.
|
||||||
|
# getattr() needed on PY36 and older (replace w/attribute access).
|
||||||
|
if getattr(module, '__file__', None) is None:
|
||||||
|
self.unmigrated_apps.add(app_config.label)
|
||||||
|
continue
|
||||||
# Module is not a package (e.g. migrations.py).
|
# Module is not a package (e.g. migrations.py).
|
||||||
if not hasattr(module, '__path__'):
|
if not hasattr(module, '__path__'):
|
||||||
self.unmigrated_apps.add(app_config.label)
|
self.unmigrated_apps.add(app_config.label)
|
||||||
|
@ -95,14 +100,11 @@ class MigrationLoader:
|
||||||
# Force a reload if it's already loaded (tests need this)
|
# Force a reload if it's already loaded (tests need this)
|
||||||
if was_loaded:
|
if was_loaded:
|
||||||
reload(module)
|
reload(module)
|
||||||
|
self.migrated_apps.add(app_config.label)
|
||||||
migration_names = {
|
migration_names = {
|
||||||
name for _, name, is_pkg in pkgutil.iter_modules(module.__path__)
|
name for _, name, is_pkg in pkgutil.iter_modules(module.__path__)
|
||||||
if not is_pkg and name[0] not in '_~'
|
if not is_pkg and name[0] not in '_~'
|
||||||
}
|
}
|
||||||
if migration_names or self.ignore_no_migrations:
|
|
||||||
self.migrated_apps.add(app_config.label)
|
|
||||||
else:
|
|
||||||
self.unmigrated_apps.add(app_config.label)
|
|
||||||
# Load migrations
|
# Load migrations
|
||||||
for migration_name in migration_names:
|
for migration_name in migration_names:
|
||||||
migration_path = '%s.%s' % (module_name, migration_name)
|
migration_path = '%s.%s' % (module_name, migration_name)
|
||||||
|
|
|
@ -337,12 +337,6 @@ Management Commands
|
||||||
* The :djadmin:`flush` and :djadmin:`sqlflush` commands now include SQL to
|
* The :djadmin:`flush` and :djadmin:`sqlflush` commands now include SQL to
|
||||||
reset sequences on SQLite.
|
reset sequences on SQLite.
|
||||||
|
|
||||||
Migrations
|
|
||||||
~~~~~~~~~~
|
|
||||||
|
|
||||||
* Migrations are now loaded also from directories without ``__init__.py``
|
|
||||||
files.
|
|
||||||
|
|
||||||
Models
|
Models
|
||||||
~~~~~~
|
~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -506,12 +506,11 @@ class LoaderTests(TestCase):
|
||||||
MIGRATION_MODULES={'migrations': 'migrations.test_migrations_namespace_package'},
|
MIGRATION_MODULES={'migrations': 'migrations.test_migrations_namespace_package'},
|
||||||
)
|
)
|
||||||
def test_loading_namespace_package(self):
|
def test_loading_namespace_package(self):
|
||||||
"""Migration directories without an __init__.py file are loaded."""
|
"""Migration directories without an __init__.py file are ignored."""
|
||||||
migration_loader = MigrationLoader(connection)
|
loader = MigrationLoader(connection)
|
||||||
self.assertEqual(
|
loader.load_disk()
|
||||||
migration_loader.graph.forwards_plan(('migrations', '0001_initial')),
|
migrations = [name for app, name in loader.disk_migrations if app == 'migrations']
|
||||||
[('migrations', '0001_initial')],
|
self.assertEqual(migrations, [])
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PycLoaderTests(MigrationTestBase):
|
class PycLoaderTests(MigrationTestBase):
|
||||||
|
|
Loading…
Reference in New Issue