Repository navigation
feat: Add dump_options= to pass model_dump options for an endpoint - #215
Merged
Merged
Conversation
- Add DumpOptions, exported from clientx and clientx.arguments, with exclude_unset, exclude_none, exclude_defaults and context. - Take it as each verb's dump_options= and pass it to every model_dump the builder makes, so a PATCH can send only the fields set and serializers can read info.context. - Raise DefinitionError when a path parameter has a default and the options set exclude_unset or exclude_defaults, which would leave the path unfilled. - Document the options, and that parameters are fields they leave out too, in the requests guide, the reference, llms.txt and the changelog. - Test each option, the path rule, the exports, and the typing contract. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
slatecipher
force-pushed
the
feat/dump-options
branch
from
December 4, 2026 16:49
f4d49db to
b5c35db
Compare
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 and why
ClientX dumps every value with pydantic's
model_dump, but an endpoint couldn't change how. Two common needs had no clean answer: a PATCH that sends only the fields a model was given, and serializers that need a setting from the endpoint (pydantic's serializationcontext). This adds adump_options=option to each verb decorator.DumpOptions, a TypedDict exported fromclientxandclientx.arguments, hasexclude_unset,exclude_none,exclude_defaultsandcontext. Themodel_dumpoptions ClientX sets itself (mode,include,by_alias,fallback) aren't in it, so type checkers reject them.dump_options=, and the builder passes it to everymodel_dump: path, query, headers, form, JSON and form JSON parts.exclude_*options leave out parameters too. Withexclude_unset, a parameter the caller didn't pass isn't sent, even with a default. This is documented.exclude_unsetorexclude_defaults, raisesDefinitionErrorwhen the class is defined. Otherwise the path would be left unfilled, and only at call time.serialize_as_anyis left out on purpose:SerializeAsAny[...]already does it per parameter, and on a spread query model the option would do nothing, silently.docs/requests.mdwith a sample, in the reference, inllms.txtand in the changelog (### Added).Builds on #212's
_guard_argument. Rebased ontomainlineafter #212, #213 and #214 merged; its tests and typing contract run with their headers andtags=changes.Testing
make checkpasses: lint, type checks, and 403 tests with the coverage gate, after the rebase.test_bodies.py: one test that runs once per option, each case sending a body different from the one without the option.test_paths.py: theDefinitionErrorfor a path parameter's default, for bothexclude_unsetandexclude_defaults.test_typing.py:dump_options=is accepted on a decorator under pyright and mypy, andDumpOptions(mode=...)is rejected.test_public_api.pylists the new export.test_docs.pyruns the new sample.🤖 Generated with Claude Code