You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(types): PostalArea TypeAdapter output is not round-trippable #1086
Re-validating that output fails because country US expects native systems zip or zip_plus_four, while the parsed legacy arm retained us_zip.
This also breaks ordinary Pydantic model dump/reconstruct cycles for TargetingOverlay.geo_postal_areas and geo_postal_areas_exclude.
Expected
TypeAdapter(PostalArea) output should validate through the same adapter. Either the legacy fused system should remain countryless on serialization, or it should normalize to the matching native system when adding country.
Context
This surfaced while applying the beta.9 object-union migration from #1084.
Classification: Bug Bucket(s): validation, client (neither label exists in the repo — noted in run summary) Status: ready-to-implement
What the experts said:
ad-tech-protocol-expert: Union arm order is inverted — PostalArea2 | PostalArea1 is the correct fix; PostalArea2.extra='forbid' plus the absence of a country field guarantees native inputs fall through cleanly. Also confirmed the upstream schema emits a global-superset System enum per arm (legacy fused tokens included), making _validate_country_system_pairing the necessary compensating control; that schema defect is a separate upstream issue.
code-reviewer: Confirmed mis-routing via PostalArea112's country: Literal['US'] = 'US' default swallowing the legacy input. Additionally flagged that the same arm-ordering bug exists in the generated postal_area.PostalArea RootModel (line 418), which is what TargetingOverlay.geo_postal_areas / geo_postal_areas_exclude actually use — the aliases.py fix does not cover that path. Also identified a missing raw-dict test case (existing test uses model-instance path, not TypeAdapter(PostalArea).validate_python(dict)).
My take: Two-site fix required — one line in aliases.py (non-generated, safe to edit directly) and a post-generate step for the generated PostalArea RootModel. Both experts converge; the change is non-breaking because it corrects a mis-routing that causes a broken serialization, not a deliberate behavior change.
Implementation scope:
src/adcp/types/aliases.py:597 — Change PostalArea1 | PostalArea2 → PostalArea2 | PostalArea1. The safety guarantee: PostalArea2.extra='forbid' + no country field means any native input (with country) is immediately rejected by the legacy arm and falls through to PostalArea1. Legacy inputs (with a CountryFusedPostalCodeSystem token and no country) now route to PostalArea2 first, serialize without injecting a country default, and round-trip cleanly.
scripts/post_generate_fixes.py (or nearest equivalent) — Apply the same arm-order swap to PostalArea at postal_area.py:418 post-generation, since TargetingOverlay.geo_postal_areas and geo_postal_areas_exclude use the generated class, not the alias. Do not hand-edit generated_poc/.
tests/test_postal_area_compat.py — Add a raw-dict round-trip test: TypeAdapter(PostalArea).validate_python({"system": "us_zip", "values": ["10001"]}) → dump should contain no country key and re-validate through the same adapter without error.
Changelog note: serialized form of legacy inputs changes (no longer injects country); callers comparing against the buggy {"country": "US", "system": "us_zip", ...} dump need updating.
Activity
bokelley commentedon Aug 25, 2026
Triage
Classification: Bug
Bucket(s): validation, client (neither label exists in the repo — noted in run summary)
Status: ready-to-implement
What the experts said:
PostalArea2 | PostalArea1is the correct fix;PostalArea2.extra='forbid'plus the absence of acountryfield guarantees native inputs fall through cleanly. Also confirmed the upstream schema emits a global-supersetSystemenum per arm (legacy fused tokens included), making_validate_country_system_pairingthe necessary compensating control; that schema defect is a separate upstream issue.PostalArea112'scountry: Literal['US'] = 'US'default swallowing the legacy input. Additionally flagged that the same arm-ordering bug exists in the generatedpostal_area.PostalAreaRootModel (line 418), which is whatTargetingOverlay.geo_postal_areas/geo_postal_areas_excludeactually use — thealiases.pyfix does not cover that path. Also identified a missing raw-dict test case (existing test uses model-instance path, notTypeAdapter(PostalArea).validate_python(dict)).My take: Two-site fix required — one line in
aliases.py(non-generated, safe to edit directly) and a post-generate step for the generatedPostalAreaRootModel. Both experts converge; the change is non-breaking because it corrects a mis-routing that causes a broken serialization, not a deliberate behavior change.Implementation scope:
src/adcp/types/aliases.py:597— ChangePostalArea1 | PostalArea2→PostalArea2 | PostalArea1. The safety guarantee:PostalArea2.extra='forbid'+ nocountryfield means any native input (withcountry) is immediately rejected by the legacy arm and falls through toPostalArea1. Legacy inputs (with aCountryFusedPostalCodeSystemtoken and nocountry) now route toPostalArea2first, serialize without injecting acountrydefault, and round-trip cleanly.scripts/post_generate_fixes.py(or nearest equivalent) — Apply the same arm-order swap toPostalAreaatpostal_area.py:418post-generation, sinceTargetingOverlay.geo_postal_areasandgeo_postal_areas_excludeuse the generated class, not the alias. Do not hand-editgenerated_poc/.tests/test_postal_area_compat.py— Add a raw-dict round-trip test:TypeAdapter(PostalArea).validate_python({"system": "us_zip", "values": ["10001"]})→ dump should contain nocountrykey and re-validate through the same adapter without error.country); callers comparing against the buggy{"country": "US", "system": "us_zip", ...}dump need updating.pytest tests/test_postal_area_compat.py -v,mypy src/adcp/types/aliases.py,ruff check .Triaged by Claude Code. Session: https://claude.ai/code/session_01V6nSRt9E4hkVRB9hJkGyNF
Generated by Claude Code
fix(sdk): complete object union and structured error handling (#1093)