Repository navigation
Conversation
…ls decode Serialize with round_trip=True on both the default path and the ToJsonOptions path, so that from_payload can validate what to_payload wrote: computed fields are left out (validation recomputes them) and Json[...] fields are written as JSON strings.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This branch has not been deployed
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.
What was changed
PydanticJSONPlainPayloadConverter.to_payloadnow passesround_trip=Truetopydantic_core.to_json(no options) and toSchemaSerializer.to_json(ToJsonOptionsset). In that mode pydantic leaves computed fields out and writesJson[...]fields as JSON strings, sofrom_payloadcan validate whatto_payloadwrote. Theto_payloaddocstring says so, and there is achangelog/fixedfragment.Why?
Computed fields were written to payloads and then read back as input keys: models with
extra="forbid"failed withextra_forbidden, and models withextra="allow"decoded with the computed value stored again as an extra.Json[...]fields were written as objects and failed withjson_type. Details, and the alternatives I tried, are in #2052.This changes payload bytes: computed fields are no longer written, and
Json[...]fields are strings. Python receivers recompute computed fields on decode; anything reading the payload JSON directly (UI, CLI, other SDKs) no longer sees them. Decoding is unchanged, so payloads already in histories decode as they do today. On pydantic 2.0 to 2.3,round_trip=Truestill writes computed fields, so there onlyJson[...]fields change.Checklist
Closes [Bug] Pydantic converter writes computed fields that models with extra="forbid" then reject #2052
How was this tested:
New test
test_payload_validates_back_to_valueintests/contrib/pydantic/test_pydantic.py, for no options,ToJsonOptions()andToJsonOptions(exclude_unset=True), with four values: anextra="forbid"model with a computed field, a list of them, anextra="allow"model with a computed field, and a model with aJson[dict[str, int]]field. It checks that the payload decodes to an equal value, then the exact bytes.ValidationError, 3 unequal values). With it: 12 passed.tests/contrib/pydanticwith a local dev server: 51 passed. The keep aliases and inf/nan when ToJsonOptions is set #2039 tests pass unchanged.tests/test_converter.py,tests/test_serialization_context.py,tests/test_plugins.py, andtests/worker/test_workflow.py -k pydantic: 80 passed.poe lintclean.Json[...]fields round-trip on all six.No. The
to_payloaddocstring and the changelog fragment describe the change.