From 079f3243577be01068543a43d1bfb42bcf84b8b3 Mon Sep 17 00:00:00 2001 From: Sanket Saurav Date: Sat, 5 May 2018 17:03:20 +0530 Subject: [PATCH] Fixed #28913 -- Fixed error handling when MIGRATIONS_MODULES specifies a nonexistent top-level package. --- AUTHORS | 1 + django/db/migrations/writer.py | 2 +- tests/migrations/test_commands.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index ff7763b2fd..91d572d78b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -722,6 +722,7 @@ answer newbie questions, and generally made Django that much better: Ryno Mathee Sam Newman Sander Dijkhuis + Sanket Saurav Sarthak Mehrish schwank@gmail.com Scot Hacker diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index aa296db8c5..d056e00646 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -240,7 +240,7 @@ class MigrationWriter: missing_dirs.insert(0, existing_dirs.pop(-1)) try: base_module = import_module(".".join(existing_dirs)) - except ImportError: + except (ImportError, ValueError): continue else: try: diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 8a77624e34..933c00eada 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -1116,6 +1116,16 @@ class MakeMigrationsTests(MigrationTestBase): # Command output indicates the migration is created. self.assertIn(" - Create model SillyModel", out.getvalue()) + @override_settings(MIGRATION_MODULES={'migrations': 'some.nonexistent.path'}) + def test_makemigrations_migrations_modules_nonexistent_toplevel_package(self): + msg = ( + 'Could not locate an appropriate location to create migrations ' + 'package some.nonexistent.path. Make sure the toplevel package ' + 'exists and can be imported.' + ) + with self.assertRaisesMessage(ValueError, msg): + call_command('makemigrations', 'migrations', empty=True, verbosity=0) + def test_makemigrations_interactive_by_default(self): """ The user is prompted to merge by default if there are conflicts and