Skip to content

types: make_versioned_base should omit optional None values #1055

Description

@bokelley

Problem

The new beta.5 make_versioned_base() gives non-required fields a None
default and nullable Python annotation, but its bundled-schema validator sends
an explicitly supplied None into JSON Schema as null. Most AdCP optional
fields permit omission, not null.

Released-wheel reproduction:

from adcp.types.versioned import make_versioned_base

ListCreatives31 = make_versioned_base("3.1", "ListCreativesRequest")

assert ListCreatives31.model_fields["account"].default is None
ListCreatives31(account=None)

Result:

pydantic.ValidationError: account: None is not of type 'object'

The same occurs for context=None, filters=None, and other omittable
top-level fields. This is surprising for a generated Pydantic base whose field
advertises T | None = None, and it breaks normal adopter construction that
passes optional function arguments directly into the request model.

Expected behavior

For a non-required field whose JSON Schema does not admit null, explicit
Python None should normalize to omission before bundled-schema validation and
wire serialization:

request = ListCreatives31(account=None)
assert "account" not in request.model_dump()

Required nullable fields must still preserve None on the wire, so a global
exclude_none=True is insufficient. The factory already computes required
fields and has each property schema; it can distinguish omittable-only fields
from required nullable ones when normalizing the top-level payload.

Please add tests for both sides:

  • optional non-nullable ListCreativesRequest.account=None is omitted; and
  • a required field whose schema explicitly permits null remains present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions