Open cobycloud opened 1 year ago
I got this issue. And my workaround is patch two methods:
patch_crudrouter
def get_pk_type_patch(schema: Type[PYDANTIC_SCHEMA], pk_field: str) -> Any:
try:
return schema.__fields__[pk_field].annotation
except KeyError:
return int
from pydantic import create_model
def schema_factory_patch(
schema_cls: Type[T], pk_field_name: str = "id", name: str = "Create"
) -> Type[T]:
"""
Is used to create a CreateSchema which does not contain pk
"""
fields = {
name: (f.annotation, ...)
for name, f in schema_cls.__fields__.items()
if name != pk_field_name
}
name = schema_cls.__name__ + name
schema: Type[T] = create_model(__model_name=name, **fields) # type: ignore
return schema
Injection
import fastapi_crudrouter
fastapi_crudrouter.core._utils.get_pk_type = get_pk_type_patch
fastapi_crudrouter.core._utils.schema_factory = schema_factory_patch
fastapi_crudrouter.core._base.schema_factory = schema_factory_patch
it works
import fastapi_crudrouter
fastapi_crudrouter.core._utils.get_pk_type = get_pk_type_patch
fastapi_crudrouter.core._utils.schema_factory = schema_factory_patch
fastapi_crudrouter.core._base.schema_factory = schema_factory_patch
It helps: https://github.com/awtkns/fastapi-crudrouter/issues/189#issuecomment-1779496250 Thanks a lot
I took this part for my diploma) from pydantic import create_model def schema_factory_patch( schema_cls: Type[T], pk_field_name: str = "id", name: str = "Create" ) -> Type[T]: """ Is used to create a CreateSchema which does not contain pk """
fields = {
name: (f.annotation, ...)
for name, f in schema_cls.__fields__.items()
if name != pk_field_name
}
name = schema_cls.__name__ + name
schema: Type[T] = create_model(__model_name=name, **fields) # type: ignore
return schema
Issue Statement
Incompatible with pydantic v2. Unable to start containerized uvicorn due to AttributeError. This occurs because pydantic's FieldInfo object does not have the attribute 'type_' Please see: pydantic.fields.FieldInfo
This can be observed by adding the following line on startup:
print(Potato.__fields__)
The output follows:
Code
Error