Skip to content

bug(types): AdCPBaseModel's -> Any model_serializer erases every serialization JSON schema #1243

Closed

Description

@bokelley

Summary

In 8.0.0b18, AdCPBaseModel declares a wrap model serializer annotated -> Any:

# adcp/types/base.py
@model_serializer(mode="wrap")
def _notification_config_wire_defaults(self, handler: SerializerFunctionWrapHandler) -> Any:

Pydantic derives a model's serialization-mode JSON schema from a wrap serializer's return annotation. Any means "unknown shape", so every AdCPBaseModel subclass now emits {} from model_json_schema(mode="serialization"). Validation-mode schemas are unaffected.

Minimal reproduction

from typing import Any
from pydantic import BaseModel, SerializerFunctionWrapHandler, model_serializer

class Typed(BaseModel):
    a: int
    @model_serializer(mode="wrap")
    def s(self, handler: SerializerFunctionWrapHandler) -> Any: return handler(self)

class Unannotated(BaseModel):
    a: int
    @model_serializer(mode="wrap")
    def s(self, handler: SerializerFunctionWrapHandler): return handler(self)

Typed.model_json_schema(mode="serialization")        # {}
Unannotated.model_json_schema(mode="serialization")  # {'properties': {'a': ...}, 'required': ['a'], ...}

Impact

Anyone publishing a response schema built from SDK types gets untyped objects. Embedded Sales Agent exports its management API as OpenAPI: regenerating it on b18 collapses 24 response component schemas to {} (0 on b9), including CreativeFormatDiscoveryError, all five SignalVendor*PricingOption variants, and TrustedMatch. Request schemas stay intact, which is what points at serialization mode. Codegen and response validation against the spec lose all type information for those objects, including error recovery semantics and billing-adjacent pricing fields.

Fix

Drop the return annotation (the reproduction above shows Pydantic then derives the schema from the model's fields), or otherwise give the serializer a return type Pydantic can project. A regression test asserting that a representative subclass's serialization schema is non-empty would keep it fixed.

Activity

  1. added
    bug
    claude-triaging
    on Sep 29, 2026
  2. bokelley commented on Sep 29, 2026

    @bokelley
    ContributorAuthor

    Triage

    Classification: Bug
    Bucket(s): client (client label not in repo — flagged in run summary)
    Status: ready-to-implement

    What the experts said:

    • code-reviewer: Non-breaking to drop -> Any; -> dict[str, Any] does NOT fix the collapse (Pydantic emits {"type": "object"}, not field schema) and would be a type lie since the method returns non-dict on the early-exit branch. Missing regression test is a blocker. Method name nit: _notification_config_wire_defaults implies narrow scope but fires on every subclass.
    • dx-expert: Blocker severity — 24 OpenAPI response component schemas silently collapse to {}, breaking codegen and response validation for anyone exporting mode="serialization" schemas (e.g., FastAPI/Starlette routes). Fix A (drop annotation) is correct; regression test assertion should check "properties" or "$defs" is present.

    My take: Bug is confirmed via uv run python — model_json_schema(mode="serialization") returns {} on any AdCPBaseModel subclass. Both experts converge: drop the annotation, add a test. Change is non-breaking; runtime serialization is unaffected.

    Implementation scope:

    • src/adcp/types/base.py:278 — remove -> Any from _notification_config_wire_defaults; add a one-line comment: # No return annotation: Pydantic derives the schema from fields. -> Any would collapse model_json_schema(mode="serialization") to {}.
    • Add tests/test_serialization_schema.py: assert a concrete AdCPBaseModel subclass's model_json_schema(mode="serialization") is non-empty and contains "properties" or "$defs". Failure message should name the wrap serializer annotation as the likely culprit.
    • Verify src/adcp/types/canonical_creative.py wrap serializer is unaffected (it is — no -> Any on that path).
    • Use a fix: conventional-commit prefix so release-please generates a CHANGELOG entry.
    • Run: pytest tests/test_serialization_schema.py, mypy src/, ruff check ., black --check .
    • Non-breaking: serializer runtime behavior is unchanged; SerializerFunctionWrapHandler.__call__ returns Any so mypy infers Any on the unannotated method — no type-checker regression.

    Triaged by Claude Code. Session: https://claude.ai/code/session_014W91pZQHLicyffUzzCQbAh


    Generated by Claude Code

  3. added and removed
    claude-triaging
    on Sep 29, 2026
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

    bugclaude-triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions