Opened 2 months ago
Closed 2 months ago
#35756 closed Bug (duplicate)
Auto reload raises TypeError: unhashable type: 'types.SimpleNamespace'
Reported by: | Paul Petersik | Owned by: | |
---|---|---|---|
Component: | Utilities | Version: | 5.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The iter_modules_and_files
function from django.utils.autoreload
raises TypeError: unhashable type: 'types.SimpleNamespace'
when a types.SimpleNamespace
is put into sys.modules
.
This is for instance the case when the zipp>=3.18.2
package is used (see https://github.com/jaraco/zipp/blob/d66007a66b7dbd88e69eaf59faae8b614cba256d/zipp/compat/overlay.py#L23) which is used by importlib_meta>=8.5.0
(see https://github.com/python/importlib_metadata/blob/90073b1aa7a49cc5fdbdc0e6e871f39e461b9422/pyproject.toml#L21)
The error can be reproduced by putting from zipp.compat.overlay import zipfile
somewhere in your django project.
This problem was already discussed and analyzed on stackoverflow:
https://stackoverflow.com/questions/78977665/django-autoreload-raises-typeerror-unhashable-type-types-simplenamespace/78977785#78977785
Change History (3)
comment:1 by , 2 months ago
Description: | modified (diff) |
---|
comment:2 by , 2 months ago
comment:3 by , 2 months ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I can replicate an error, but as Tim mentioned, I will mark this is a duplicate of #35085
-
tests/utils_tests/test_autoreload.py
a b class TestIterModulesAndFiles(SimpleTestCase): 148 148 self.addCleanup(lambda: sys.modules.pop("time_proxy", None)) 149 149 list(autoreload.iter_all_python_module_files()) # No crash. 150 150 151 def test_unhashable_objects_in_sys_module(self): 152 name_space = types.SimpleNamespace() 153 sys.modules["name_space"] = name_space # type: ignore[assignment] 154 self.addCleanup(lambda: sys.modules.pop("name_space", None)) 155 list(autoreload.iter_all_python_module_files()) # Crash 156 151 157 def test_module_without_spec(self): 152 158 module = types.ModuleType("test_module")
Related: The same crash was reported In #35085. It was concluded that PyATS's monkey-patching of
sys.modules
wasn't something proper that Django should account for.