Skip to content

REST: Delegate parsing to Pydantic #1847

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

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

Fokko
Copy link
Contributor

@Fokko Fokko commented Mar 25, 2025

Rationale for this change

Right now we deserialize the JSON into a dict, which is then passed into the Pydantic model. It is better to fully delegate this to pydantic because it is probably faster, and we can detect when models are created from json or from Python dicts.

Required by #1770

This is also a recommendation by Pydantic itself: https://docs.pydantic.dev/latest/concepts/performance/#in-general-use-model_validate_json-not-model_validatejsonloads

Are these changes tested?

Existing tests

Are there any user-facing changes?

No

Right now we deserialize the JSON into a dict, which is then passed
into the Pydantic model. It is better to fully delegate this to
pydantic because it is probably faster, and we can detect when
models are created from json or from Python dicts.

Required by apache#1770
Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

LGTM
I double checked all regex matching \*\*.*\.json is in rest.py and this PR addressed all of them

@Fokko Fokko merged commit 172d9a7 into apache:main Mar 25, 2025
7 checks passed
@Fokko Fokko deleted the fd-delegate-parsing-to-pydantic branch March 25, 2025 19:39
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.

2 participants