-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
Hello!
Just tried to use your package to cache frequent GET requests in my FastApi app.
Endpoint looks like this:
@router.get("/{id}", response_model=Malt)
@cache_one_hour()
def get_malt_by_id(*, db: Session = Depends(get_db), id: UUID4, ):
return actions.malt.get(db=db, id=id) # actions returns SQLAlchemy 'Malt' model which is converted to Pydantic 'Malt' schema after that, also tries to return Malt.from_orm(actions...) - same result
When I try to make requests I can see following in the logs:
FAILED_TO_CACHE_KEY: Object of type <class '....db.models.dictionaries.malt.Malt'> is not JSON-serializable: key=cache:mypkg.api.routes.dictionaries.malts.get_malt_by_id(id=7af9090c-dcb5-4778-b090-5b6890618566)
Pydantic schema looks like following (basically it is much more complex but I removed everything but name and still get same result.
class Malt(BaseModel):
name: str
class Config:
orm_mode = True
My example seems to be quite the same to your example with User model from documentation. So why doesn't it work?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels