Skip to content

model_dump emits schema defaults the wire document omitted (143 fields in 60 schemas), which changes digested and echoed bytes #1613

Closed

Description

@bokelley

Observed

The generator writes every schema default into the generated field (sandbox: bool = False, timezone: ... = 'inventory_local', separator: str = ','), and AdCPBaseModel.model_dump(mode="json") emits every field. A schema-valid document that omitted a defaulted property therefore comes back with the property present:

core/account-ref.json            /sandbox: (absent) -> false
core/targeting.json              /daypart_targets/0/timezone: (absent) -> "inventory_local"
media-buy/product-purchase.json  /targeting_overlay/daypart_targets/0/timezone: (absent) -> "inventory_local"
media-buy/accept-proposal-request.json /opportunity/status: (absent) -> "closed"
creative/list-creatives-request.json   /assignment_limit: (absent) -> 50

Found by the wire round-trip sweep added in #1610's PR (tests/conformance/_round_trip.py, run with --variants): under the SDK's default dump settings, 143 distinct (schema, field) pairs across 60 schemas gain a value the input did not carry. This is the largest remaining round-trip class after the wire-preserving scalar types landed.

Why it matters

For a reader, "omitted" and "present with the schema default" describe the same document. For a digest or an echo they do not: core/canonical-proposal.json binds terms_digest to SHA-256(JCS(commercial_terms)), and commercial_terms reaches targeting.json (daypart_targets[].timezone, age_restriction.verification_required) and canonical-optimization-goal.json (event_sources[].value_factor). A buyer that parses a committed proposal with the SDK and re-dumps commercial_terms to verify terms_digest gets a mismatch whenever the seller omitted any of those six defaulted properties. core/package-format-snapshot.json (267 defaults reachable under tracker_execution_contract / the product format declaration) and governance/check-governance-request.json (7) have the same exposure. #1449 (item 3) reported the same mechanism from the other side: dumping a validated ProductFormatDeclaration "adds every branch default ... to the published format, which changes the wire".

Proposed design

Non-breaking (9.x): document and test the "dump as received" recipe, which the sweep confirms leaves no default_emitted residue:

model.model_dump(mode="json", exclude_unset=True, exclude_none=False, by_alias=True)

exclude_unset leaves off every field the document did not set; exclude_none=False keeps an explicit null the schema admits (fields the schema refuses null on are already excluded by NoExplicitNull); by_alias writes the wire name. The round-trip suite measures this recipe and asserts its residue is only dropped unknown fields.

Breaking (10.0 candidate): leave an optional, non-required, defaulted property unset on dump unless the caller set it — i.e. make exclude_unset the default for fields the schema does not require. Required fields with a generator-injected default (literal discriminators, status) must keep emitting, so this is per-field, not a global exclude_unset=True. Attribute reads (model.sandbox is False) are unchanged either way.

Evidence and the measuring tool: python -m tests.conformance._round_trip --variants (see tests/conformance/test_wire_round_trip.py, where this class is accepted with a reference to this issue).

Activity

  1. added
    no-triageSkip the Claude triage bot — human or designated agent will handle this issue
    on Oct 25, 2026
  2. bokelley commented on Oct 28, 2026

    @bokelley
    ContributorAuthor

    Fixed on next by #1683: generated wire-required fields are marked, and an unset schema-optional default is left off the dump. It ships in SDK 10.0.0b1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    no-triageSkip the Claude triage bot — human or designated agent will handle this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions