Fixed #29091 -- Fixed makemigrations crash if migrations directory doesn't have __init__.py.

Regression in aadd3aeb2b.
This commit is contained in:
Tim Graham 2018-01-30 18:28:04 -05:00
parent de59132afc
commit 0a37ea56d0
4 changed files with 11 additions and 1 deletions

View File

@ -48,7 +48,7 @@ class MigrationQuestioner:
elif hasattr(migrations_module, "__path__"): elif hasattr(migrations_module, "__path__"):
if len(migrations_module.__path__) > 1: if len(migrations_module.__path__) > 1:
return False 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") return not any(x.endswith(".py") for x in filenames if x != "__init__.py")
def ask_not_null_addition(self, field_name, model_name): def ask_not_null_addition(self, field_name, model_name):

View File

@ -24,3 +24,6 @@ Bugfixes
* Fixed a regression where ``contrib.auth.authenticate()`` crashes if an * Fixed a regression where ``contrib.auth.authenticate()`` crashes if an
authentication backend doesn't accept ``request`` and a later one does authentication backend doesn't accept ``request`` and a later one does
(:ticket:`29071`). (:ticket:`29071`).
* Fixed a regression where ``makemigrations`` crashes if a migrations directory
doesn't have an ``__init__.py`` file (:ticket:`29091`).

View File

@ -853,6 +853,13 @@ class MakeMigrationsTests(MigrationTestBase):
call_command("makemigrations", stdout=out) call_command("makemigrations", stdout=out)
self.assertIn("0001_initial.py", out.getvalue()) 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): def test_makemigrations_migrations_announce(self):
""" """
makemigrations announces the migration at the default verbosity level. makemigrations announces the migration at the default verbosity level.