Skip to content

fix(types): request model account fields still return removed AccountReference RootModel #1087

Closed

Description

@bokelley

Version

adcp==8.0.0b9

Reproduction

from adcp.types import AccountReference, GetProductsRequest

request = GetProductsRequest(
    buying_mode="wholesale",
    brief="test",
    account={"account_id": "acc_123"},
)

print(AccountReference)
print(GetProductsRequest.model_fields["account"].annotation)
print(type(request.account), request.account)

Observed:

  • Public AccountReference is the new composable union alias.
  • GetProductsRequest.model_fields["account"].annotation is still the generated outer RootModel type.
  • request.account is AccountReference(root=AccountReference1(...)), not AccountReferenceById.

The same stale annotation is present on make_versioned_base("3.1", "GetProductsRequest").

Expected

SDK request models that expose an account field should use the public composable union and return its concrete arms, consistent with the beta.9 migration contract in #1084. Otherwise adopter code must support both the new public union and the removed wrapper depending on whether it validates the field directly or through an SDK request model.

Context

This surfaced while applying the beta.9 object-union migration from #1084.

Activity

  1. added
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Aug 25, 2026
  2. bokelley commented on Aug 25, 2026

    @bokelley
    ContributorAuthor

    Triage

    Classification: Bug
    Bucket(s): client (label not found in repo — flagged as gap)
    Status: ready-to-implement

    What the experts said:

    • code-reviewer: Fix belongs in _ergonomic.py patching layer using BeforeValidator + model_rebuild(force=True), consistent with existing patterns; 20+ models affected means the generator script also needs updating; test assertions on .account type need revision
    • dx-expert: Inconsistency between direct-validation and request-model-field paths is a first-class DX breakage for beta.9 adopters — the migration guide from fix(types)!: expose object unions without RootModel #1084 sets an expectation that .account yields concrete arms, and any code that does isinstance(request.account, AccountReferenceById) silently fails with the current wrapper

    My take: This is a clean follow-on to #1084 — the generated AccountReference RootModel was intentionally removed from the public surface but the request model field annotations were not updated to match. The fix is well-bounded once the pattern is established, and it should complete before beta.9 adoption widens.

    Implementation scope:

    • Root cause: generated_poc/*/request.py files bind account to account_ref.AccountReference (the RootModel wrapper); the patching layer in _ergonomic.py does not override this field, so validation returns AccountReference(root=AccountReference1(...)) instead of the concrete arm.

    • Recommended fix: In src/adcp/types/_ergonomic.py (and its generator scripts/generate_ergonomic_coercion.py), add an account field patch for each affected request model using:

      from adcp.types._generated import AccountReference1, AccountReference2
      from adcp.types.generated_poc.core import account_ref as _account_ref
      _AccountReferenceUnion = Annotated[
          AccountReference1 | AccountReference2,
          BeforeValidator(_account_ref.AccountReference._validate_python),
      ]

      Then for each model: _patch_field_annotation(ModelClass, "account", _AccountReferenceUnion) followed by model_rebuild(force=True). Alternatively, centralise in _forward_compat.py as a second apply-at-import pass over the same model list — fewer generator changes but mixes concerns slightly.

    • Scope of affected models (~20+): GetProductsRequest, CreateMediaBuyRequest, UpdateMediaBuyRequest, SyncCatalogsRequest, SyncAudiencesRequest, SyncEventSourcesRequest, GetMediaBuyDeliveryRequest, GetMediaBuysRequest, GetAccountFinancialsRequest, SyncGovernanceRequest, SyncAccountsRequest (two fields), ListAccountsRequest, ReportUsageRequest, ActivateSignalRequest, GetSignalsRequest, AcquireRightsRequest, UpdateRightsRequest, collection-domain requests, and ListTasksRequest / GetTaskStatusRequest.

    • make_versioned_base note: The make_versioned_base("3.1", "GetProductsRequest") path derives fields from the bundled JSON schema, not from runtime annotations, so it may not pick up the _ergonomic.py patch automatically — verify whether the versioned base shares the same class object or constructs a fresh one; a separate patch may be needed there.

    • Required checks: pytest tests/ (update any assertions that currently expect AccountReference(root=...) to expect the concrete arm), mypy src/, ruff check . + black --check ..

    • Non-breaking rationale: Wire format is unchanged. The behavior change (RootModel → concrete arm on .account) is part of the announced beta.9 migration contract from fix(types)!: expose object unions without RootModel #1084 (which was itself tagged !). Within 8.0.0b9, completing this migration is expected.


    Triaged by Claude Code. Session: https://claude.ai/code/${CLAUDE_CODE_REMOTE_SESSION_ID}


    Generated by Claude Code

  3. added
    bugSomething isn't working
    and removed
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Aug 25, 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions