tortoise-orm
tortoise-orm copied to clipboard
"TypeError: Cannot instantiate typing.Union" with "OneToOneNullableRelation"
Describe the bug
We get a TypeError when the field OneToOneNullableRelation is used.
Traceback (most recent call last):
File "/root/senran_dev/run.py", line 5, in <module>
from bot import SenranBot
File "/root/senran_dev/bot.py", line 10, in <module>
import db
File "/root/senran_dev/db/__init__.py", line 1, in <module>
from .models import *
File "/root/senran_dev/db/models.py", line 21, in <module>
class User(BaseModel):
File "/root/senran_dev/db/models.py", line 23, in User
activated_guild = fields.OneToOneNullableRelation(model_name='models.Guild')
File "/usr/lib/python3.8/typing.py", line 729, in __call__
result = self.__origin__(*args, **kwargs)
File "/usr/lib/python3.8/typing.py", line 339, in __call__
raise TypeError(f"Cannot instantiate {self!r}")
TypeError: Cannot instantiate typing.Union
Process finished with exit code 1
To Reproduce
Create a model with a OneToOneNullableRelation relation
Expected behavior The model and the field should work properly.
Additional context Nothing else to add.
This is still an ongoing problem. I am using Python 3.10.6. I believe it has something to do with typing changes on this version of Python.