Skip to content

Optional fields redeclared in canonical_creative lose the never-null marker, so nested dumps emit null (follow-up to #1587) #1620

Closed

Description

@bokelley

Follow-up to #1587 / #1591.

Observed

Optional fields that adcp.types.canonical_creative redeclares don't carry the never-null marker (_RefuseJsonNull) that their generated counterparts do. They aren't omitted when unset in a nested dump, so a plain-pydantic parent emits null for them. Their schemas don't admit null.

from pydantic import BaseModel

from adcp.types import Product


class Envelope(BaseModel):
    products: list[Product]


product = Product.model_construct(product_id="p", name="n", description="d")
print("direct dump nulls:", sorted(k for k, v in product.model_dump(mode="json").items() if v is None))
body = Envelope.model_construct(products=[product]).model_dump(mode="json")
print("nested dump nulls:", sorted(k for k, v in body["products"][0].items() if v is None))
direct dump nulls: []
nested dump nulls: ['placements']

Optional fields checked on 9.1.0 with no marker (compare Product.channels, which has one):

  • Product.placements
  • Placement.format_options
  • CreateMediaBuyRequest.packages
  • UpdateMediaBuyRequest.packages and new_packages
  • GetProductsResponse.products
  • GetProductsRequest.filters
  • ListCreativesRequest.filters

Expected

Redeclared optional fields keep the generated field's never-null metadata, so #1591's guarantee ("never-null fields omit None from every serializer") also holds for the canonical-creative types.

Impact

The Embedded Sales Agent keeps its own Product serializer that strips these nulls, because its wire responses nest SDK products in its own models.

Activity

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 labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions