Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(json): revert eager check #2926

Merged
merged 5 commits into from
Aug 25, 2022
Merged

Conversation

aarnphm
Copy link
Member

@aarnphm aarnphm commented Aug 19, 2022

This PR removes an eager check for a pydantic object.

Our JSONEncoder should already handle pydantic object lazily

https://bentoml.slack.com/archives/CKRANBHPH/p1660930201114169

Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
@aarnphm aarnphm requested a review from a team as a code owner August 19, 2022 18:24
@aarnphm aarnphm requested review from ssheng and removed request for a team August 19, 2022 18:24
yubozhao
yubozhao previously approved these changes Aug 19, 2022
@codecov
Copy link

codecov bot commented Aug 19, 2022

Codecov Report

Merging #2926 (f3999ca) into main (372b530) will decrease coverage by 0.11%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2926      +/-   ##
==========================================
- Coverage   70.82%   70.70%   -0.12%     
==========================================
  Files         104      104              
  Lines        9435     9442       +7     
==========================================
- Hits         6682     6676       -6     
- Misses       2753     2766      +13     
Impacted Files Coverage Δ
bentoml/_internal/io_descriptors/json.py 89.24% <50.00%> (ø)
bentoml/_internal/configuration/containers.py 76.53% <0.00%> (-3.26%) ⬇️
bentoml/_internal/service/loader.py 71.85% <0.00%> (-1.49%) ⬇️
bentoml/_internal/bento/bento.py 90.97% <0.00%> (-0.91%) ⬇️
bentoml/_internal/service/openapi/specification.py 92.95% <0.00%> (-0.29%) ⬇️
bentoml/_internal/server/service_app.py 87.85% <0.00%> (-0.09%) ⬇️
bentoml/_internal/service/openapi/__init__.py 97.91% <0.00%> (-0.09%) ⬇️
bentoml/_internal/service/service.py 96.80% <0.00%> (+1.06%) ⬆️

Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
yubozhao
yubozhao previously approved these changes Aug 19, 2022
Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
import pydantic

# This is to prevent cases where custom JSON encoder is used.
if isinstance(obj, pydantic.BaseModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use if self._pydantic_model

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct right? checking object instance is independent of whether self._pydantic_model is set or not.

validate should be raised from error

Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
@aarnphm aarnphm requested a review from parano August 22, 2022 17:11
Copy link
Contributor

@sauyon sauyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@@ -241,14 +241,16 @@ async def from_http_request(self, request: Request) -> JSONType:
pydantic_model = self._pydantic_model.parse_obj(json_obj)
return pydantic_model
except pydantic.ValidationError as e:
raise BadInput(f"Invalid JSON input received: {e}") from None
raise BadInput(f"Invalid JSON input received: {e}") from e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, do you know why this was None before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sauyon @aarnphm https://peps.python.org/pep-0415/ that was for better exception context

@aarnphm aarnphm merged commit 3219add into bentoml:main Aug 25, 2022
@aarnphm aarnphm deleted the fix/remove-pydantic branch August 25, 2022 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants