Skip to content

Commit

Permalink
fix: fix bug of serialization error and runner can't be shutdown (#5103)
Browse files Browse the repository at this point in the history
* fix: fix a bug that runner app can't be shutdown correctly

Signed-off-by: Frost Ming <me@frostming.com>

* fix: remove unused class

Signed-off-by: Frost Ming <me@frostming.com>

* fix: serialization mode

Signed-off-by: Frost Ming <me@frostming.com>

---------

Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming authored Nov 28, 2024
1 parent 1233d73 commit 66ac916
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 31 deletions.
29 changes: 0 additions & 29 deletions src/_bentoml_sdk/_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/_bentoml_sdk/io_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/bentoml/_internal/server/runner_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 66ac916

Please sign in to comment.