Repository navigation
Description
Follow-up split off from #807. Surfaced when regenerating types against the refreshed 3.1.0-beta.3 schema cache (#821).
Two coupled bugs in the codegen pipeline
1. scripts/post_generate_fixes.py strips ProtocolEnvelope import without re-adding
_remove_original_response_class (lines 1581-1591) removes the import when the generator's placeholder class Foo(AdcpVersionEnvelope, ProtocolEnvelope): pass is stripped. Then _write_if_needed appends manual class definitions (some of which reference ProtocolEnvelope — e.g., CreateMediaBuyResponse3 at line 1918) without re-adding the import.
Works today only because the previously-committed _generated.py was generated from an older schema snapshot where datamodel-codegen happened to emit the import for other reasons. New schema shape doesn't.
Symptom on regen: NameError: name 'ProtocolEnvelope' is not defined in:
media_buy/create_media_buy_response.py- Several
brand/*_response.pyfiles - Several
content_standards/*_response.pyfiles - A handful of
media_buy/*_response.pyfiles
Fix sketch (verified in a throwaway branch):
# In _write_if_needed, after appending snippet:
combined = source.rstrip() + snippet.rstrip() + "\n"
protocol_import = "from ..core.protocol_envelope import ProtocolEnvelope\n"
if "ProtocolEnvelope" in combined and protocol_import not in combined:
combined = combined.replace(
"from ..core.version_envelope import AdcpVersionEnvelope\n",
protocol_import + "from ..core.version_envelope import AdcpVersionEnvelope\n",
1,
)
target.write_text(combined)2. src/adcp/types/aliases.py carries stale defensive lookups
Multiple aliases use the pattern getattr(_g, "FooResponse1", _g.FooResponse) where neither name exists in the regenerated _generated.py. Example at aliases.py:101:
AcquireRightsResponse1 = getattr(_g, "AcquireRightsResponse1", _g.AcquireRightsResponse)
# AttributeError: module 'adcp.types._generated' has no attribute 'AcquireRightsResponse'Schema-driven names have moved upstream; the fallback name never materialized. Each affected alias needs to be checked against the regenerated _generated.py and either re-pointed or deleted.
Why bundled together
You can't regen types until (1) is fixed (codegen produces non-importing files). Once (1) is fixed and the regen runs, (2) surfaces as the next import error. Both need to land before the regenerated types are committed.
Acceptance
-
scripts/post_generate_fixes.pyre-adds theProtocolEnvelopeimport when appending classes that reference it -
aliases.pydefensive lookups updated to current generated names (or removed where the fallback is the wrong shape) -
python scripts/generate_types.pysucceeds from a clean state -
python -c "from adcp.types import _generated; from adcp.types import aliases"imports cleanly -
pytest tests/test_code_generation.py tests/test_asset_aliases_stable.py tests/test_schemas_version_pin.py -vpasses - The original handrolled-alias audit from chore(types): schema sync against 3.1.0-beta.3 + drop obsolete handrolled aliases #807 can finally proceed against a working regen
Refs
- Parent issue: chore(types): schema sync against 3.1.0-beta.3 + drop obsolete handrolled aliases #807
- Schema sync PR that surfaced this: chore(schemas): resync 3.1.0-beta.3 cache + fix broken manifest patch (refs #807) #821
- Release line context: release: cut 6.0.0-beta.1 line for AdCP 3.1 features #802 (6.0-beta cut)
Activity
bokelley commentedon May 23, 2026
Active fix candidate: #824. I updated the PR branch against current main so CI can rerun on the current base. The PR body currently says Refs #822 rather than Closes #822, so if it merges as-is we should close this issue manually or update the PR body before merge.
bokelley commentedon Jun 6, 2026
Both bugs are resolved on main. (1)
_sync_protocol_envelope_importinscripts/post_generate_fixes.pyre-adds theProtocolEnvelopeimport when a restored arm references it (handles the existing-import, future-import-only, and no-import cases);create_media_buy_response.pycarries the import. (2) The stale two-arggetattr(_g, 'X', _g.Y)fallbacks are gone —aliases.pynow uses a single_generated_alias(name, fallback)try/except helper. Regen-from-clean against rc.9 succeeds. Closing as fixed.