diff options
| author | Tim Graham <timograham@gmail.com> | 2018-02-05 13:16:57 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-11-17 14:46:04 -0500 |
| commit | 8deb0a8efd948855310c45064b109090596510e4 (patch) | |
| tree | b70df9d53599fd3c235ff727f4f9f1e5b486e8dc | |
| parent | b9e248975f3190fee245b30313c2744bf836bb1c (diff) | |
[1.11.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.py | 5 | ||||
| -rw-r--r-- | django/db/migrations/questioner.py | 3 |
2 files changed, 5 insertions, 3 deletions
diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py index bbbde07a98..be39b09e26 100644 --- a/django/db/migrations/loader.py +++ b/django/db/migrations/loader.py @@ -89,8 +89,9 @@ class MigrationLoader(object): 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 df08508a10..6668e33fda 100644 --- a/django/db/migrations/questioner.py +++ b/django/db/migrations/questioner.py @@ -46,7 +46,8 @@ class MigrationQuestioner(object): 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: |
