From 0a37ea56d05208e31ed2f29fdffca65b6d92fa2e Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 30 Jan 2018 18:28:04 -0500 Subject: [PATCH] Fixed #29091 -- Fixed makemigrations crash if migrations directory doesn't have __init__.py. Regression in aadd3aeb2ba3153e35bd805c80c901f289a6f333. --- django/db/migrations/questioner.py | 2 +- docs/releases/2.0.2.txt | 3 +++ tests/migrations/test_commands.py | 7 +++++++ tests/migrations/test_migrations_no_init/.gitkeep | 0 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/migrations/test_migrations_no_init/.gitkeep diff --git a/django/db/migrations/questioner.py b/django/db/migrations/questioner.py index 337d50844d7..2c34a8fd89b 100644 --- a/django/db/migrations/questioner.py +++ b/django/db/migrations/questioner.py @@ -48,7 +48,7 @@ class MigrationQuestioner: elif hasattr(migrations_module, "__path__"): if len(migrations_module.__path__) > 1: return False - filenames = os.listdir(migrations_module.__path__[0]) + filenames = os.listdir(list(migrations_module.__path__)[0]) return not any(x.endswith(".py") for x in filenames if x != "__init__.py") def ask_not_null_addition(self, field_name, model_name): diff --git a/docs/releases/2.0.2.txt b/docs/releases/2.0.2.txt index 000236af2cc..c6633491d21 100644 --- a/docs/releases/2.0.2.txt +++ b/docs/releases/2.0.2.txt @@ -24,3 +24,6 @@ Bugfixes * Fixed a regression where ``contrib.auth.authenticate()`` crashes if an authentication backend doesn't accept ``request`` and a later one does (:ticket:`29071`). + +* Fixed a regression where ``makemigrations`` crashes if a migrations directory + doesn't have an ``__init__.py`` file (:ticket:`29091`). diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 8caa0b5deb9..8a77624e341 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -853,6 +853,13 @@ class MakeMigrationsTests(MigrationTestBase): call_command("makemigrations", stdout=out) self.assertIn("0001_initial.py", out.getvalue()) + def test_makemigrations_no_init(self): + """Migration directories without an __init__.py file are allowed.""" + out = io.StringIO() + with self.temporary_migration_module(module='migrations.test_migrations_no_init'): + call_command('makemigrations', stdout=out) + self.assertIn('0001_initial.py', out.getvalue()) + def test_makemigrations_migrations_announce(self): """ makemigrations announces the migration at the default verbosity level. diff --git a/tests/migrations/test_migrations_no_init/.gitkeep b/tests/migrations/test_migrations_no_init/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d