From 66ac9165d5d0bd877fbb8601973f1d657fc0c0f8 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 28 Nov 2024 13:44:40 +0800 Subject: [PATCH] fix: fix bug of serialization error and runner can't be shutdown (#5103) * fix: fix a bug that runner app can't be shutdown correctly Signed-off-by: Frost Ming * fix: remove unused class Signed-off-by: Frost Ming * fix: serialization mode Signed-off-by: Frost Ming --------- Signed-off-by: Frost Ming --- src/_bentoml_sdk/_pydantic.py | 29 ---------------------- src/_bentoml_sdk/io_models.py | 2 +- src/bentoml/_internal/server/runner_app.py | 2 +- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/src/_bentoml_sdk/_pydantic.py b/src/_bentoml_sdk/_pydantic.py index 8152e868d9a..f5c39108a8d 100644 --- a/src/_bentoml_sdk/_pydantic.py +++ b/src/_bentoml_sdk/_pydantic.py @@ -2,7 +2,6 @@ import typing as t -from pydantic import GenerateSchema from pydantic._internal import _known_annotated_metadata from .typing_utils import get_args @@ -195,31 +194,3 @@ def pathlib_prepare_pydantic_annotations( # PIL image pil_prepare_pydantic_annotations, ] - - -class BentoMLPydanticGenerateSchema(GenerateSchema): - def _get_prepare_pydantic_annotations_for_known_type( - self, obj: t.Any, annotations: t.Iterable[t.Any] - ) -> tuple[t.Any, list[t.Any]] | None: - # Check for hashability - try: - hash(obj) - except TypeError: - # obj is definitely not a known type if this fails - return None - # try path preparer first to override the default one - res = pathlib_prepare_pydantic_annotations( - obj, annotations, self._config_wrapper.config_dict - ) - if res is not None: - return res - - res = super()._get_prepare_pydantic_annotations_for_known_type(obj, annotations) - if res is not None: - return res - - for preparer in CUSTOM_PREPARE_METHODS: - res = preparer(obj, annotations, self._config_wrapper.config_dict) - if res is not None: - return res - return None diff --git a/src/_bentoml_sdk/io_models.py b/src/_bentoml_sdk/io_models.py index 354ef299623..a1f42285e49 100644 --- a/src/_bentoml_sdk/io_models.py +++ b/src/_bentoml_sdk/io_models.py @@ -421,7 +421,7 @@ def model_dump(self, **kwargs: t.Any) -> dict[str, t.Any]: return super().model_dump(**kwargs)["root"] def model_dump_json(self, **kwargs: t.Any) -> str: - return json.dumps(self.model_dump(**kwargs)) + return json.dumps(self.model_dump(mode="json", **kwargs)) @classmethod def model_validate(cls, obj: t.Any, **kwargs: t.Any) -> t.Self: diff --git a/src/bentoml/_internal/server/runner_app.py b/src/bentoml/_internal/server/runner_app.py index 1765635d563..fe88f5c3c9b 100644 --- a/src/bentoml/_internal/server/runner_app.py +++ b/src/bentoml/_internal/server/runner_app.py @@ -116,7 +116,7 @@ def on_startup(self) -> list[LifecycleHook]: @property def on_shutdown(self) -> list[LifecycleHook]: - on_shutdown: list[LifecycleHook] = [self.runner.destroy] + on_shutdown: list[LifecycleHook] = [with_app_arg(self.runner.destroy)] for dispatcher in self.dispatchers.values(): on_shutdown.append(with_app_arg(dispatcher.shutdown)) on_shutdown.extend(super().on_shutdown)