Implement a provider / provider_name version of serializable models#176
Closed
anbuzin wants to merge 2 commits into
Closed
Implement a provider / provider_name version of serializable models#176anbuzin wants to merge 2 commits into
anbuzin wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
msullivan
reviewed
Jun 17, 2026
msullivan
left a comment
Contributor
There was a problem hiding this comment.
I have some comments about the interface but I still think this is the way forward
4a5989f to
9d725e2
Compare
msullivan
reviewed
Jun 18, 2026
Comment on lines
+206
to
+282
| def model_dump( | ||
| self, | ||
| *, | ||
| mode: Literal["json", "python"] | str = "python", | ||
| include: Any = None, | ||
| exclude: Any = None, | ||
| context: Any | None = None, | ||
| by_alias: bool | None = None, | ||
| exclude_unset: bool = False, | ||
| exclude_defaults: bool = False, | ||
| exclude_none: bool = False, | ||
| exclude_computed_fields: bool = False, | ||
| round_trip: bool = False, | ||
| warnings: bool | Literal["none", "warn", "error"] = True, | ||
| fallback: Callable[[Any], Any] | None = None, | ||
| serialize_as_any: bool = False, | ||
| ) -> dict[str, Any]: | ||
| if mode == "json" and not self._is_serializable: | ||
| raise ConfigurationError( | ||
| "Model was constructed with a live provider/protocol and " | ||
| "cannot be serialized. Use provider_name/provider_args instead." | ||
| ) | ||
| return super().model_dump( | ||
| mode=mode, | ||
| include=include, | ||
| exclude=exclude, | ||
| context=context, | ||
| by_alias=by_alias, | ||
| exclude_unset=exclude_unset, | ||
| exclude_defaults=exclude_defaults, | ||
| exclude_none=exclude_none, | ||
| exclude_computed_fields=exclude_computed_fields, | ||
| round_trip=round_trip, | ||
| warnings=warnings, | ||
| fallback=fallback, | ||
| serialize_as_any=serialize_as_any, | ||
| ) | ||
|
|
||
| def model_dump_json( | ||
| self, | ||
| *, | ||
| indent: int | None = None, | ||
| ensure_ascii: bool = False, | ||
| include: Any = None, | ||
| exclude: Any = None, | ||
| context: Any | None = None, | ||
| by_alias: bool | None = None, | ||
| exclude_unset: bool = False, | ||
| exclude_defaults: bool = False, | ||
| exclude_none: bool = False, | ||
| exclude_computed_fields: bool = False, | ||
| round_trip: bool = False, | ||
| warnings: bool | Literal["none", "warn", "error"] = True, | ||
| fallback: Callable[[Any], Any] | None = None, | ||
| serialize_as_any: bool = False, | ||
| ) -> str: | ||
| if not self._is_serializable: | ||
| raise ConfigurationError( | ||
| "Model was constructed with a live provider/protocol and " | ||
| "cannot be serialized. Use provider_name/provider_args instead." | ||
| ) | ||
| return super().model_dump_json( | ||
| indent=indent, | ||
| ensure_ascii=ensure_ascii, | ||
| include=include, | ||
| exclude=exclude, | ||
| context=context, | ||
| by_alias=by_alias, | ||
| exclude_unset=exclude_unset, | ||
| exclude_defaults=exclude_defaults, | ||
| exclude_none=exclude_none, | ||
| exclude_computed_fields=exclude_computed_fields, | ||
| round_trip=round_trip, | ||
| warnings=warnings, | ||
| fallback=fallback, | ||
| serialize_as_any=serialize_as_any, | ||
| ) |
Contributor
There was a problem hiding this comment.
Why is this needed? Shouldn't _serialize_model handle this?
| handler: pydantic.SerializerFunctionWrapHandler, | ||
| info: pydantic.SerializationInfo, | ||
| ) -> dict[str, Any]: | ||
| if info.mode == "json" and not self._is_serializable: |
Contributor
There was a problem hiding this comment.
Huh, why only json mode?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.