Fixed #29749 -- Made the migrations loader ignore files starting with a tilde or underscore.

Regression in 29150d5da8.
This commit is contained in:
Tim Graham 2018-09-11 12:51:11 -04:00 committed by GitHub
parent a4d8e412e0
commit 32fbccab40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 1 deletions

View File

@ -97,7 +97,10 @@ class MigrationLoader:
if was_loaded:
reload(module)
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
for migration_name in migration_names:
migration_path = '%s.%s' % (module_name, migration_name)

View File

@ -11,3 +11,6 @@ Bugfixes
* Fixed a regression where nonexistent joins in ``F()`` no longer raised
``FieldError`` (:ticket:`29727`).
* Fixed a regression where files starting with a tilde or underscore weren't
ignored by the migrations loader (:ticket:`29749`).

View File

@ -500,6 +500,14 @@ class LoaderTests(TestCase):
}
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):

View File

@ -0,0 +1,5 @@
from django.db import migrations
class Migration(migrations.Migration):
pass