Skip to content

Commit e8ab6c4

Browse files
authored
fix: don't try to validate non-bytes as Path (#4765)
* fix: don't try to validate non-bytes as Path Fix #4728 Signed-off-by: Frost Ming <me@frostming.com> * fix: order Signed-off-by: Frost Ming <me@frostming.com> --------- Signed-off-by: Frost Ming <me@frostming.com>
1 parent 1cb5781 commit e8ab6c4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/_bentoml_sdk/validators.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ def decode(self, obj: bytes | t.BinaryIO | UploadFile | PurePath | str) -> t.Any
143143
if (fn := getattr(obj, "name", None)) is not None
144144
else None
145145
)
146-
else:
147-
body = t.cast(bytes, obj)
146+
elif isinstance(obj, bytes):
147+
body = obj
148148
filename = None
149+
else:
150+
from pydantic_core import PydanticCustomError
151+
152+
raise PydanticCustomError("path_type", "Invalid file type")
149153
if media_type is not None and self.content_type is not None:
150154
if not fnmatch.fnmatch(media_type, self.content_type):
151155
raise ValueError(

0 commit comments

Comments
 (0)