summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-02-05 13:16:57 -0500
committerTim Graham <timograham@gmail.com>2018-06-28 10:05:46 -0400
commitcba51003de23ecefaaeb231f2adda19ea589d286 (patch)
tree7fc12478812fe25439df49073704a49b658cfc0c
parentda906ff1ae7ed3baa8362ae728fe55ea08e8f83e (diff)
[2.0.x] Refs #28814 -- Fixed migrations crash with namespace packages on Python 3.7.
Due to https://bugs.python.org/issue32303. Backport of 0f0a07ac278dc2be6da81e519188f77e2a2a00cf from master
-rw-r--r--django/db/migrations/loader.py5
-rw-r--r--django/db/migrations/questioner.py3
-rw-r--r--docs/releases/2.0.7.txt3
3 files changed, 8 insertions, 3 deletions
diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py
index 8a1cf431bd..a6fe1afc15 100644
--- a/django/db/migrations/loader.py
+++ b/django/db/migrations/loader.py
@@ -84,8 +84,9 @@ class MigrationLoader:
continue
raise
else:
- # PY3 will happily import empty dirs as namespaces.
- if not hasattr(module, '__file__'):
+ # Empty directories are namespaces.
+ # getattr() needed on PY36 and older (replace w/attribute access).
+ if getattr(module, '__file__', None) is None:
self.unmigrated_apps.add(app_config.label)
continue
# Module is not a package (e.g. migrations.py).
diff --git a/django/db/migrations/questioner.py b/django/db/migrations/questioner.py
index 9b5b9f3510..0fd377ec14 100644
--- a/django/db/migrations/questioner.py
+++ b/django/db/migrations/questioner.py
@@ -43,7 +43,8 @@ class MigrationQuestioner:
except ImportError:
return self.defaults.get("ask_initial", False)
else:
- if hasattr(migrations_module, "__file__"):
+ # getattr() needed on PY36 and older (replace with attribute access).
+ if getattr(migrations_module, "__file__", None):
filenames = os.listdir(os.path.dirname(migrations_module.__file__))
elif hasattr(migrations_module, "__path__"):
if len(migrations_module.__path__) > 1:
diff --git a/docs/releases/2.0.7.txt b/docs/releases/2.0.7.txt
index 8d06deb226..ee54f396fb 100644
--- a/docs/releases/2.0.7.txt
+++ b/docs/releases/2.0.7.txt
@@ -16,3 +16,6 @@ Bugfixes
``ModelAdmin.ordering`` (:ticket:`29428`).
* Fixed ``__regex`` and ``__iregex`` lookups with MySQL 8 (:ticket:`29451`).
+
+* Fixed migrations crash with namespace packages on Python 3.7
+ (:ticket:`28814`).