Skip to content

feat: Add dump_options= to pass model_dump options for an endpoint - #215

Merged
slatecipher merged 1 commit into
mainlinefrom
feat/dump-options
Dec 4, 2026
Merged

slatecipher merged 1 commit into
mainlinefrom
feat/dump-options

Conversation

@slatecipher

@slatecipher slatecipher commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

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 serialization context). This adds a dump_options= option to each verb decorator.

  • DumpOptions, a TypedDict exported from clientx and clientx.arguments, has exclude_unset, exclude_none, exclude_defaults and context. The model_dump options ClientX sets itself (mode, include, by_alias, fallback) aren't in it, so type checkers reject them.
  • Each verb decorator takes dump_options=, and the builder passes it to every model_dump: path, query, headers, form, JSON and form JSON parts.
  • The endpoint's parameters are fields of its request model, so the exclude_* options leave out parameters too. With exclude_unset, a parameter the caller didn't pass isn't sent, even with a default. This is documented.
  • A path parameter with a default, combined with exclude_unset or exclude_defaults, raises DefinitionError when the class is defined. Otherwise the path would be left unfilled, and only at call time.
  • serialize_as_any is left out on purpose: SerializeAsAny[...] already does it per parameter, and on a spread query model the option would do nothing, silently.
  • Documented in a new "Dump options" section of docs/requests.md with a sample, in the reference, in llms.txt and in the changelog (### Added).

Builds on #212's _guard_argument. Rebased onto mainline after #212, #213 and #214 merged; its tests and typing contract run with their headers and tags= changes.

Testing

  • make check passes: 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: the DefinitionError for a path parameter's default, for both exclude_unset and exclude_defaults.
  • test_typing.py: dump_options= is accepted on a decorator under pyright and mypy, and DumpOptions(mode=...) is rejected.
  • test_public_api.py lists the new export. test_docs.py runs the new sample.
  • A scratch script exercised each option on every route before the set of options was chosen.

🤖 Generated with Claude Code

@slatecipher slatecipher added the enhancement New feature or request label Dec 4, 2026
@slatecipher slatecipher self-assigned this Dec 4, 2026
@slatecipher slatecipher added the enhancement New feature or request label Dec 4, 2026
Base automatically changed from refactor/argument-guard to mainline December 4, 2026 16:38
- 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
slatecipher merged commit e511494 into mainline Dec 4, 2026
8 checks passed
@slatecipher
slatecipher deleted the feat/dump-options branch December 4, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant