[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
This commit is contained in:
parent
b9e248975f
commit
8deb0a8efd
@ -89,8 +89,9 @@ class MigrationLoader(object):
|
|||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
# PY3 will happily import empty dirs as namespaces.
|
# Empty directories are namespaces.
|
||||||
if not hasattr(module, '__file__'):
|
# getattr() needed on PY36 and older (replace w/attribute access).
|
||||||
|
if getattr(module, '__file__', None) is None:
|
||||||
self.unmigrated_apps.add(app_config.label)
|
self.unmigrated_apps.add(app_config.label)
|
||||||
continue
|
continue
|
||||||
# Module is not a package (e.g. migrations.py).
|
# Module is not a package (e.g. migrations.py).
|
||||||
|
@ -46,7 +46,8 @@ class MigrationQuestioner(object):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
return self.defaults.get("ask_initial", False)
|
return self.defaults.get("ask_initial", False)
|
||||||
else:
|
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__))
|
filenames = os.listdir(os.path.dirname(migrations_module.__file__))
|
||||||
elif hasattr(migrations_module, "__path__"):
|
elif hasattr(migrations_module, "__path__"):
|
||||||
if len(migrations_module.__path__) > 1:
|
if len(migrations_module.__path__) > 1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user