Skip to content

Commit

Permalink
fix latest bug
Browse files Browse the repository at this point in the history
  • Loading branch information
John Lyu committed May 9, 2024
1 parent 91ba6d7 commit 19c4d02
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
17 changes: 3 additions & 14 deletions fastapi_cache/coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

import pendulum
from fastapi.encoders import jsonable_encoder
from pydantic import BaseConfig, ValidationError, fields
from starlette.responses import JSONResponse
from starlette.templating import (
_TemplateResponse as TemplateResponse, # pyright: ignore[reportPrivateUsage]
)
class ModelField:
pass

_T = TypeVar("_T", bound=type)

Expand Down Expand Up @@ -69,7 +70,7 @@ def decode(cls, value: bytes) -> Any:
# decode_as_type method and then stores a different kind of field for a
# given type, do make sure that the subclass provides its own class
# attribute for this cache.
_type_field_cache: ClassVar[Dict[Any, fields.ModelField]] = {}
_type_field_cache: ClassVar[Dict[Any, ModelField]] = {}

@overload
@classmethod
Expand All @@ -89,18 +90,6 @@ def decode_as_type(cls, value: bytes, *, type_: Optional[_T]) -> Union[_T, Any]:
"""
result = cls.decode(value)
if type_ is not None:
try:
field = cls._type_field_cache[type_]
except KeyError:
field = cls._type_field_cache[type_] = fields.ModelField(
name="body", type_=type_, class_validators=None, model_config=BaseConfig
)
result, errors = field.validate(result, {}, loc=())
if errors is not None:
if not isinstance(errors, list):
errors = [errors]
raise ValidationError(errors, type_)
return result


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastapi-cache2"
version = "0.2.1"
version = "0.2.2"
description = "Cache for FastAPI"
authors = ["long2ice <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 19c4d02

Please sign in to comment.