Skip to content

Generated enums repeat values under _1 names (19 enums on 10.0.0b4, 17 on 9.3.0) #1782

Closed

Description

@bokelley

Codegen emits some StrEnums with the same value twice, under a second name ending in _1. For example, postal_country_system.System has zip = 'zip' and zip_1 = 'zip', and display_tag_asset.Field17 has ad_request_url_1 = 'ad_request_url'. Python turns the second member into an alias of the first. So nothing breaks at runtime, but:

  • autocomplete, docs and __members__ offer names that are not AdCP values;
  • code that switches on a member name (or serializes member.name) can see zip_1;
  • the duplicates suggest the generator merges overlapping enum lists from sibling anyOf arms without deduplicating them.

Repro

import importlib
import pkgutil
from enum import Enum

import adcp.types.domains as domains

seen: dict[str, list[str]] = {}
for module_info in pkgutil.walk_packages(domains.__path__, domains.__name__ + "."):
    try:
        module = importlib.import_module(module_info.name)
    except ImportError:  # tombstone modules for removed types
        continue
    for name, obj in vars(module).items():
        if isinstance(obj, type) and issubclass(obj, Enum) and obj.__module__ == module.__name__:
            aliases = [alias for alias, member in obj.__members__.items() if alias != member.name]
            if aliases:
                seen[f"{module.__name__}.{name}"] = aliases

print(len(seen), "enums with duplicate values")

10.0.0b4 prints 19, including:

adcp.types.domains.core.assets.asset_union.Field1 ['ad_request_url_1', 'clickthrough_url_1']
adcp.types.domains.core.assets.display_tag_asset.Field17 ['ad_request_url_1', 'clickthrough_url_1']
adcp.types.domains.core.postal_area.System ['zip_1', 'zip_plus_four_1']
adcp.types.domains.core.postal_area.System1 ['outward_1', 'full_1']
adcp.types.domains.core.postal_area.System2 ['fsa_1', 'full_1']

9.3.0 prints 17 (the postal-system enums).

Suggested fix

Deduplicate enum values when codegen merges value lists, and add a codegen check that fails when a generated enum has an alias.

Activity

  1. bokelley commented on Nov 2, 2026

    @bokelley
    ContributorAuthor

    Fixed on next by #1799 (squash 03572535): post_generate_fixes.dedupe_enum_member_values drops the _1 alias members and tests/test_generated_enums_have_no_aliases.py holds the whole generated tree to it. Ships in the next 10.0.0 beta; breaking for code that named an alias member (migration row added).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions