New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
model.update_or_create KeyError #1583
Comments
I got different errors with the following code snippet: import uuid
from tortoise import Tortoise, fields, run_async
from tortoise.models import Model
class Faqs(Model):
id = fields.UUIDField(pk=True)
question = fields.TextField(null=True)
async def run():
await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]})
await Tortoise.generate_schemas()
faq, _ = await Faqs.get_or_create(id="6aadafff-e0b9-497b-aeb2-65498a35b6f5")
# modify question
faq.question = "q111234"
# assign new id
faq.id = uuid.uuid4()
# update_or_create, KeyError
new_faq, created = await Faqs.update_or_create(id=faq.id, defaults=dict(faq))
print(dict(new_faq), created)
if __name__ == "__main__":
run_async(run()) ERROR is:
|
After change the Python version to 3.10, got the KeyError:
|
For why it raises KeyError instead of TypeError with Python<3.12, see this: https://stackoverflow.com/questions/78427983/why-does-dictid-1-id-2-sometimes-raise-keyerror-id-instead-of-a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tortoise-orm/tortoise/models.py
Line 1065 in 0c8efde
would cause KeyError for following code:
ERROR like:
The text was updated successfully, but these errors were encountered: