diff options
| author | Víðir Valberg Guðmundsson <valberg@orn.li> | 2014-06-17 17:50:31 +0200 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-06-17 09:57:15 -0700 |
| commit | 7f0c207d1b33b03b5bfe89c0e09d4f790c8a1d0a (patch) | |
| tree | 165d44e92a8b99078ca39fda85950fa86359c231 | |
| parent | aa10f57d9460f121dea2ec2635e478ed02cc18b5 (diff) | |
[1.7.x] Fixed #22577: Python 3 broke on non-module migrations directory
| -rw-r--r-- | django/db/migrations/writer.py | 6 | ||||
| -rw-r--r-- | tests/migrations/migrations_test_apps/without_init_file/migrations/.keep | 0 | ||||
| -rw-r--r-- | tests/migrations/test_writer.py | 1 |
3 files changed, 7 insertions, 0 deletions
diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index dee867929d..71f81e9e2d 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -158,6 +158,12 @@ class MigrationWriter(object): # See if we can import the migrations module directly try: migrations_module = import_module(migrations_package_name) + + # Python 3 fails when the migrations directory does not have a + # __init__.py file + if not hasattr(migrations_module, '__file__'): + raise ImportError + basedir = os.path.dirname(migrations_module.__file__) except ImportError: app_config = apps.get_app_config(self.migration.app_label) diff --git a/tests/migrations/migrations_test_apps/without_init_file/migrations/.keep b/tests/migrations/migrations_test_apps/without_init_file/migrations/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/migrations/migrations_test_apps/without_init_file/migrations/.keep diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index cd59938314..8f8437faf9 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -215,6 +215,7 @@ class WriterTests(TestCase): test_apps = [ 'migrations.migrations_test_apps.normal', 'migrations.migrations_test_apps.with_package_model', + 'migrations.migrations_test_apps.without_init_file', ] base_dir = os.path.dirname(os.path.dirname(__file__)) |
