You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I'm trying to load a module using importlib where a BaseModel is used then execution is crashed with the following traceback:
Traceback (most recent call last):
File "loader.py", line 13, in <module>
m = load_module("module_to_load.py")
File "loader.py", line 7, in load_module
spec.loader.exec_module(module) # type: ignore[union-attr]
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "module_to_load.py", line 4, in <module>
class User(BaseModel):
File "pydantic/main.py", line 274, in pydantic.main.ModelMetaclass.__new__
File "pydantic/typing.py", line 293, in pydantic.typing.resolve_annotations
def __copy__(self):
As use-case may seem strange, I'm a bit hestiating between a bug and wrong usage, but in the latter case, error message is unclear at all. Important part is that I have to import the module in this way and not in any other more standard python way in which pydantic indeed work without any issue.
Thanks
EDIT:
Indeed, if we add sys.modules["mymodule"] = module to load_module as suggested here, there is no issue, anymore.
I have to figure out what would be the impact of doing that for my goal.
The text was updated successfully, but these errors were encountered:
Checks
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:If I'm trying to load a module using
importlib
where a BaseModel is used then execution is crashed with the following traceback:How to repro:
loader.py
file with the following contentmodule_to_load.py
:python loader.py
As use-case may seem strange, I'm a bit hestiating between a bug and wrong usage, but in the latter case, error message is unclear at all. Important part is that I have to import the module in this way and not in any other more standard python way in which pydantic indeed work without any issue.
Thanks
EDIT:
Indeed, if we add
sys.modules["mymodule"] = module
toload_module
as suggested here, there is no issue, anymore.I have to figure out what would be the impact of doing that for my goal.
The text was updated successfully, but these errors were encountered: