Skip to content

Commit 19c4d02

Browse files
author
John Lyu
committed
fix latest bug
1 parent 91ba6d7 commit 19c4d02

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

fastapi_cache/coder.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
import pendulum
1717
from fastapi.encoders import jsonable_encoder
18-
from pydantic import BaseConfig, ValidationError, fields
1918
from starlette.responses import JSONResponse
2019
from starlette.templating import (
2120
_TemplateResponse as TemplateResponse, # pyright: ignore[reportPrivateUsage]
2221
)
22+
class ModelField:
23+
pass
2324

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

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

7475
@overload
7576
@classmethod
@@ -89,18 +90,6 @@ def decode_as_type(cls, value: bytes, *, type_: Optional[_T]) -> Union[_T, Any]:
8990
9091
"""
9192
result = cls.decode(value)
92-
if type_ is not None:
93-
try:
94-
field = cls._type_field_cache[type_]
95-
except KeyError:
96-
field = cls._type_field_cache[type_] = fields.ModelField(
97-
name="body", type_=type_, class_validators=None, model_config=BaseConfig
98-
)
99-
result, errors = field.validate(result, {}, loc=())
100-
if errors is not None:
101-
if not isinstance(errors, list):
102-
errors = [errors]
103-
raise ValidationError(errors, type_)
10493
return result
10594

10695

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fastapi-cache2"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
description = "Cache for FastAPI"
55
authors = ["long2ice <[email protected]>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)