[2.1.x] Fixed #29749 -- Made the migrations loader ignore files starting with a tilde or underscore.
Regression in 29150d5da880ac1db15e47052330790cf1b802d2. Backport of 32fbccab406b680bc0a0a8d39a9b95c3a08bbc5a from master
This commit is contained in:
parent
5cd053600e
commit
5bbcf83fce
@ -97,7 +97,10 @@ class MigrationLoader:
|
|||||||
if was_loaded:
|
if was_loaded:
|
||||||
reload(module)
|
reload(module)
|
||||||
self.migrated_apps.add(app_config.label)
|
self.migrated_apps.add(app_config.label)
|
||||||
migration_names = {name for _, name, is_pkg in pkgutil.iter_modules(module.__path__) if not is_pkg}
|
migration_names = {
|
||||||
|
name for _, name, is_pkg in pkgutil.iter_modules(module.__path__)
|
||||||
|
if not is_pkg and name[0] not in '_~'
|
||||||
|
}
|
||||||
# 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)
|
||||||
|
@ -11,3 +11,6 @@ Bugfixes
|
|||||||
|
|
||||||
* Fixed a regression where nonexistent joins in ``F()`` no longer raised
|
* Fixed a regression where nonexistent joins in ``F()`` no longer raised
|
||||||
``FieldError`` (:ticket:`29727`).
|
``FieldError`` (:ticket:`29727`).
|
||||||
|
|
||||||
|
* Fixed a regression where files starting with a tilde or underscore weren't
|
||||||
|
ignored by the migrations loader (:ticket:`29749`).
|
||||||
|
@ -500,6 +500,14 @@ class LoaderTests(TestCase):
|
|||||||
}
|
}
|
||||||
self.assertEqual(plan, expected_plan)
|
self.assertEqual(plan, expected_plan)
|
||||||
|
|
||||||
|
@override_settings(MIGRATION_MODULES={'migrations': 'migrations.test_migrations_private'})
|
||||||
|
def test_ignore_files(self):
|
||||||
|
"""Files prefixed with underscore, tilde, or dot aren't loaded."""
|
||||||
|
loader = MigrationLoader(connection)
|
||||||
|
loader.load_disk()
|
||||||
|
migrations = [name for app, name in loader.disk_migrations if app == 'migrations']
|
||||||
|
self.assertEqual(migrations, ['0001_initial'])
|
||||||
|
|
||||||
|
|
||||||
class PycLoaderTests(MigrationTestBase):
|
class PycLoaderTests(MigrationTestBase):
|
||||||
|
|
||||||
|
0
tests/migrations/test_migrations_private/.util.py
Normal file
0
tests/migrations/test_migrations_private/.util.py
Normal file
5
tests/migrations/test_migrations_private/0001_initial.py
Normal file
5
tests/migrations/test_migrations_private/0001_initial.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
pass
|
0
tests/migrations/test_migrations_private/_util.py
Normal file
0
tests/migrations/test_migrations_private/_util.py
Normal file
0
tests/migrations/test_migrations_private/~util.py
Normal file
0
tests/migrations/test_migrations_private/~util.py
Normal file
Loading…
x
Reference in New Issue
Block a user