Skip to content

types: ergonomics after the RootModel change (cached union validation, list roots, alias names) #1437

Description

@bokelley

Summary

Three small type ergonomics we hit moving the Embedded Sales Agent from 8.0.0 to 9.0.0b1. docs/types-9-migration.md covers the semantics; these are about day-to-day use.

  1. Validating a union root needs a hand-rolled cached TypeAdapter. The guide says to use TypeAdapter(X).validate_python(...) for unions such as WholesaleFeedEvent or VendorPricingOptionUnion. Building a TypeAdapter per call is expensive, so every adopter ends up writing the same functools.cache wrapper (we added validate_adcp_union(union, payload)). A public helper (for example adcp.types.validate_union(X, payload) with a cached adapter), or a module-level X_ADAPTER exported beside each union alias, would remove that.
  2. List roots are still RootModel. Scalar roots became str/int subclasses, but list-valued roots still need .root. Two we hit: the delivery status_filter (RootModel[list[MediaBuyStatus]]) and the signal forecast point's dimensions. Code now mixes "read it directly" and "unwrap .root" depending on the root's JSON type. Converting list roots too (as list subclasses or plain list[...] aliases), or listing which roots stay RootModel in the types guide, would make the rule predictable. Related to codegen: a $ref into another file's properties generates a RootModel wrapper, so 27 of TargetingOverlayInput's 37 fields disagree with TargetingOverlay #1362.
  3. Union alias naming is inconsistent between import paths. adcp.types exports VendorPricingOptionUnion, while the generated module calls the same union VendorPricingOption, and adcp.types has no VendorPricingOption. Pick one name, or export both.

No activity

Activity on this issue will appear here.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions