Closed 0x587 closed 1 year ago
Hello, I encountered the same problem and by downgrading pydentic to 1.10.6
it got solved. I think this is only a temporary solution and somebody should definitely look into it.
Duplicate with: https://github.com/awtkns/fastapi-crudrouter/issues/189
Thanks for your great advice. I found that solving this problem only requires downgrading pydentic to a version below 2.0. Use the command
pip install "pydantic==1.*"
The problem occurs when pydantic2.x modifies
BaseModel.__fields__
I provide a feasible solution here, just modify the schema_factory
function on line 22 of core/_utils.py
.
# for handle pydantic 2.x migration
from pydantic import __version__ as pydantic_version
if int(pydantic_version.split('.')[0]) >= 2:
# pydantic 2.x
fields = {
fk: (fv.annotation, ...)
for fk,fv in schema_cls.model_fields.items()
if fk != pk_field_name
}
else:
# pydantic 1.x
fields = {
f.name: (f.type_, ...)
for f in schema_cls.__fields__.values()
if f.name != pk_field_name
}
I'll submit a Pull Request to fix this later.
I got this problem when I just try the demo! Python3.11.4