From 19c4d0271a7065684a1961f4b1bb90c15a6f5d17 Mon Sep 17 00:00:00 2001 From: John Lyu Date: Thu, 9 May 2024 14:09:42 +0800 Subject: [PATCH] fix latest bug --- fastapi_cache/coder.py | 17 +++-------------- pyproject.toml | 2 +- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/fastapi_cache/coder.py b/fastapi_cache/coder.py index 904fc69..178fe26 100644 --- a/fastapi_cache/coder.py +++ b/fastapi_cache/coder.py @@ -15,11 +15,12 @@ from typing import ( 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) @@ -69,7 +70,7 @@ class Coder: # 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 @@ -89,18 +90,6 @@ class Coder: """ 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 diff --git a/pyproject.toml b/pyproject.toml index c49fd44..003157d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fastapi-cache2" -version = "0.2.1" +version = "0.2.2" description = "Cache for FastAPI" authors = ["long2ice "] license = "Apache-2.0"