Closed jamesbraza closed 2 months ago
Examples from the website are failing with pydantic 2.7, maybe this should be documented?
Has anyone found any work arounds in the mean time?
Yeah, I can confirm that bug is real
Problem seems to be that something changed in processing of models in pydantic, and it recognises Model.Meta
as attribute and sends it to validation, which fails, because models generated by pydantic_model_creator
has extra="forbid"
, not allowing extra attributes.
As very hacky workaround - you can run
from tortoise.contrib.pydantic import PydanticModel
PydanticModel.model_config["extra"] = "ignore"
somewhere on init of your code, before pydantic_model_creator
I also created issue with pydantic - https://github.com/pydantic/pydantic/issues/9300 - may be they will be able to provide some insights into why this is happening and how can we bypass that without switching from extra="forbid"
They confirmed that it is indeed pydantic bug, which will be fixed in 2.7.1, which should be released today
I'll close issue once I confirm that fix works
Yeah, fixed with pydantic 2.7.1
Thanks for making that issue @abondar and ensuring the community is back up and running. What do you think of:
extra
for Pydantic in TortoiseSo taking this https://github.com/tortoise/tortoise-orm/blob/0.20.0/pyproject.toml#L75 to something like pydantic = "^2.0,!=2.7.0"
Sounds good, right now I am working on some clean up and rooting out one elusive bug, when I will be ready to make release I'll try to incorporate this extra
Describe the bug
Pydantic 2.7.0 (released today) broke
pydantic_model_creator
, it now throws this error:To Reproduce
I am using
tortoise-orm==0.20.0
and Python 3.12.2. The below code runs with Pydantic 2.6.4, but not with Pydantic 2.7.0:Expected behavior
pydantic_model_creator
to work with Pydantic 2.7Additional context
N/a