Kaydet (Commit) d73176a8 authored tarafından Marten Kenbeek's avatar Marten Kenbeek Kaydeden (comit) Tim Graham

Fixed #24848 -- Fixed ValueError for faulty migrations module.

Added apps to unmigrated apps if the migrations module is a file
or a folder missing __init__.py.

Thanks to Ernest0x for the bug report.
üst 73b5b0b4
...@@ -79,9 +79,11 @@ class MigrationLoader(object): ...@@ -79,9 +79,11 @@ class MigrationLoader(object):
else: else:
# PY3 will happily import empty dirs as namespaces. # PY3 will happily import empty dirs as namespaces.
if not hasattr(module, '__file__'): if not hasattr(module, '__file__'):
self.unmigrated_apps.add(app_config.label)
continue 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)
continue continue
# 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:
......
...@@ -11,3 +11,6 @@ Bugfixes ...@@ -11,3 +11,6 @@ Bugfixes
* Fixed ``BaseRangeField.prepare_value()`` to use each ``base_field``’s * Fixed ``BaseRangeField.prepare_value()`` to use each ``base_field``’s
``prepare_value()`` method (:ticket:`24841`). ``prepare_value()`` method (:ticket:`24841`).
* Fixed crash during :djadmin:`makemigrations` if a migrations module either
is missing ``__init__.py`` or is a file (:ticket:`24848`).
...@@ -164,12 +164,20 @@ class LoaderTests(TestCase): ...@@ -164,12 +164,20 @@ class LoaderTests(TestCase):
def test_load_module_file(self): def test_load_module_file(self):
with override_settings(MIGRATION_MODULES={"migrations": "migrations.faulty_migrations.file"}): with override_settings(MIGRATION_MODULES={"migrations": "migrations.faulty_migrations.file"}):
MigrationLoader(connection) loader = MigrationLoader(connection)
self.assertIn(
"migrations", loader.unmigrated_apps,
"App with migrations module file not in unmigrated apps."
)
@skipIf(six.PY2, "PY2 doesn't load empty dirs.") @skipIf(six.PY2, "PY2 doesn't load empty dirs.")
def test_load_empty_dir(self): def test_load_empty_dir(self):
with override_settings(MIGRATION_MODULES={"migrations": "migrations.faulty_migrations.namespace"}): with override_settings(MIGRATION_MODULES={"migrations": "migrations.faulty_migrations.namespace"}):
MigrationLoader(connection) loader = MigrationLoader(connection)
self.assertIn(
"migrations", loader.unmigrated_apps,
"App missing __init__.py in migrations module not in unmigrated apps."
)
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"}) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"})
def test_loading_squashed(self): def test_loading_squashed(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment