mirror of
https://github.com/django/django.git
synced 2025-03-12 10:22:37 +00:00
Fixed #25109 -- Stopped silencing explicitly specified migration modules import errors.
Thanks Tim for the review.
This commit is contained in:
parent
a72411e140
commit
0d7929266e
@ -54,11 +54,16 @@ class MigrationLoader(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def migrations_module(cls, app_label):
|
def migrations_module(cls, app_label):
|
||||||
|
"""
|
||||||
|
Return the path to the migrations module for the specified app_label
|
||||||
|
and a boolean indicating if the module is specified in
|
||||||
|
settings.MIGRATION_MODULE.
|
||||||
|
"""
|
||||||
if app_label in settings.MIGRATION_MODULES:
|
if app_label in settings.MIGRATION_MODULES:
|
||||||
return settings.MIGRATION_MODULES[app_label]
|
return settings.MIGRATION_MODULES[app_label], True
|
||||||
else:
|
else:
|
||||||
app_package_name = apps.get_app_config(app_label).name
|
app_package_name = apps.get_app_config(app_label).name
|
||||||
return '%s.%s' % (app_package_name, MIGRATIONS_MODULE_NAME)
|
return '%s.%s' % (app_package_name, MIGRATIONS_MODULE_NAME), False
|
||||||
|
|
||||||
def load_disk(self):
|
def load_disk(self):
|
||||||
"""
|
"""
|
||||||
@ -69,7 +74,7 @@ class MigrationLoader(object):
|
|||||||
self.migrated_apps = set()
|
self.migrated_apps = set()
|
||||||
for app_config in apps.get_app_configs():
|
for app_config in apps.get_app_configs():
|
||||||
# Get the migrations module directory
|
# Get the migrations module directory
|
||||||
module_name = self.migrations_module(app_config.label)
|
module_name, explicit = self.migrations_module(app_config.label)
|
||||||
if module_name is None:
|
if module_name is None:
|
||||||
self.unmigrated_apps.add(app_config.label)
|
self.unmigrated_apps.add(app_config.label)
|
||||||
continue
|
continue
|
||||||
@ -79,7 +84,8 @@ class MigrationLoader(object):
|
|||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
# I hate doing this, but I don't want to squash other import errors.
|
# I hate doing this, but I don't want to squash other import errors.
|
||||||
# Might be better to try a directory check directly.
|
# Might be better to try a directory check directly.
|
||||||
if "No module named" in str(e) and MIGRATIONS_MODULE_NAME in str(e):
|
if ((explicit and self.ignore_no_migrations) or (
|
||||||
|
not explicit and "No module named" in str(e) and MIGRATIONS_MODULE_NAME in str(e))):
|
||||||
self.unmigrated_apps.add(app_config.label)
|
self.unmigrated_apps.add(app_config.label)
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
@ -37,7 +37,7 @@ class MigrationQuestioner(object):
|
|||||||
app_config = apps.get_app_config(app_label)
|
app_config = apps.get_app_config(app_label)
|
||||||
except LookupError: # It's a fake app.
|
except LookupError: # It's a fake app.
|
||||||
return self.defaults.get("ask_initial", False)
|
return self.defaults.get("ask_initial", False)
|
||||||
migrations_import_path = MigrationLoader.migrations_module(app_config.label)
|
migrations_import_path, _ = MigrationLoader.migrations_module(app_config.label)
|
||||||
if migrations_import_path is None:
|
if migrations_import_path is None:
|
||||||
# It's an application with migrations disabled.
|
# It's an application with migrations disabled.
|
||||||
return self.defaults.get("ask_initial", False)
|
return self.defaults.get("ask_initial", False)
|
||||||
|
@ -221,7 +221,7 @@ class MigrationWriter(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def basedir(self):
|
def basedir(self):
|
||||||
migrations_package_name = MigrationLoader.migrations_module(self.migration.app_label)
|
migrations_package_name, _ = MigrationLoader.migrations_module(self.migration.app_label)
|
||||||
|
|
||||||
if migrations_package_name is None:
|
if migrations_package_name is None:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
@ -205,6 +205,22 @@ class LoaderTests(TestCase):
|
|||||||
self.assertEqual(migration_loader.migrated_apps, set())
|
self.assertEqual(migration_loader.migrated_apps, set())
|
||||||
self.assertEqual(migration_loader.unmigrated_apps, {'migrated_app'})
|
self.assertEqual(migration_loader.unmigrated_apps, {'migrated_app'})
|
||||||
|
|
||||||
|
@override_settings(
|
||||||
|
INSTALLED_APPS=['migrations.migrations_test_apps.migrated_app'],
|
||||||
|
MIGRATION_MODULES={'migrated_app': 'missing-module'},
|
||||||
|
)
|
||||||
|
def test_explicit_missing_module(self):
|
||||||
|
"""
|
||||||
|
If a MIGRATION_MODULES override points to a missing module, the error
|
||||||
|
raised during the importation attempt should be propagated unless
|
||||||
|
`ignore_no_migrations=True`.
|
||||||
|
"""
|
||||||
|
with self.assertRaisesMessage(ImportError, 'missing-module'):
|
||||||
|
migration_loader = MigrationLoader(connection)
|
||||||
|
migration_loader = MigrationLoader(connection, ignore_no_migrations=True)
|
||||||
|
self.assertEqual(migration_loader.migrated_apps, set())
|
||||||
|
self.assertEqual(migration_loader.unmigrated_apps, {'migrated_app'})
|
||||||
|
|
||||||
@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):
|
||||||
"Tests loading a squashed migration"
|
"Tests loading a squashed migration"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user