mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
fix latest bug
This commit is contained in:
@@ -15,11 +15,12 @@ from typing import (
|
|||||||
|
|
||||||
import pendulum
|
import pendulum
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from pydantic import BaseConfig, ValidationError, fields
|
|
||||||
from starlette.responses import JSONResponse
|
from starlette.responses import JSONResponse
|
||||||
from starlette.templating import (
|
from starlette.templating import (
|
||||||
_TemplateResponse as TemplateResponse, # pyright: ignore[reportPrivateUsage]
|
_TemplateResponse as TemplateResponse, # pyright: ignore[reportPrivateUsage]
|
||||||
)
|
)
|
||||||
|
class ModelField:
|
||||||
|
pass
|
||||||
|
|
||||||
_T = TypeVar("_T", bound=type)
|
_T = TypeVar("_T", bound=type)
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ class Coder:
|
|||||||
# decode_as_type method and then stores a different kind of field for a
|
# 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
|
# given type, do make sure that the subclass provides its own class
|
||||||
# attribute for this cache.
|
# attribute for this cache.
|
||||||
_type_field_cache: ClassVar[Dict[Any, fields.ModelField]] = {}
|
_type_field_cache: ClassVar[Dict[Any, ModelField]] = {}
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -89,18 +90,6 @@ class Coder:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
result = cls.decode(value)
|
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
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "fastapi-cache2"
|
name = "fastapi-cache2"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
description = "Cache for FastAPI"
|
description = "Cache for FastAPI"
|
||||||
authors = ["long2ice <long2ice@gmail.com>"]
|
authors = ["long2ice <long2ice@gmail.com>"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user