{"record":{"id":"decc354d6cf5cab6","repo":"apache/beam","slug":"could-not-determine-schema-for-type-hints-element-types-r","errorCode":null,"errorMessage":"Could not determine schema for type hints {element_types!r}: Inconsistent names: {name_set}","messagePattern":"Could not determine schema for type hints (.+?): Inconsistent names: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/schemas.py","lineNumber":739,"sourceCode":"def union_schema_type(element_types):\n  \"\"\"Returns a schema whose fields are the union of each corresponding field.\n\n  element_types must be a set of schema-aware types whose fields have the\n  same naming and ordering.\n  \"\"\"\n  named_fields_and_types = []\n  for t in element_types:\n    n = named_fields_from_element_type(t)\n    if named_fields_and_types and len(named_fields_and_types[-1]) != len(n):\n      raise TypeError(\"element types has different number of fields\")\n    named_fields_and_types.append(n)\n\n  union_fields_and_types = []\n  for field in zip(*named_fields_and_types):\n    names, types = zip(*field)\n    name_set = set(names)\n    if len(name_set) != 1:\n      raise TypeError(\n          f\"Could not determine schema for type hints {element_types!r}: \"\n          f\"Inconsistent names: {name_set}\")\n    union_fields_and_types.append(\n        (next(iter(name_set)), typehints.Union[types]))\n  return named_tuple_from_schema(named_fields_to_schema(union_fields_and_types))\n\n\nclass _Ephemeral:\n  \"\"\"Helper class for wrapping unpicklable objects.\"\"\"\n  def __init__(self, obj):\n    self.obj = obj\n\n  def __reduce__(self):\n    return _Ephemeral, (None, )\n\n\n# Registry of typings for a schema by UUID\nclass LogicalTypeRegistry(object):","sourceCodeStart":721,"sourceCodeEnd":757,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/schemas.py#L721-L757","documentation":"union_schema_type() zips the fields of all element types and requires that the fields at each position share exactly one name. If the names at a position differ across element types, it raises TypeError with the offending name set. This ensures the unified union schema has unambiguous field names.","triggerScenarios":"Calling union_schema_type() (or schema coercion of a Union type hint) where element types have the same field count but different field names at the same position, e.g. Union[Row(a=int), Row(b=int)] or Union[NamedTuple(id=int), NamedTuple(key=int)].","commonSituations":"Renaming a field in one copy of a NamedTuple but not another; hand-writing Union annotations over structurally similar but differently named record types; combining types from two libraries that model the same concept with different field names.","solutions":["Rename fields so every element type in the Union uses identical field names in the same order.","Align the types with a single shared base NamedTuple/Row schema and use that in the annotation.","Map each type to a common representation with a DoFn/map before schema inference."],"exampleFix":"// before\nclass A(NamedTuple):\n  id: int\n\nclass B(NamedTuple):\n  key: int\n\n# Union[A, B] -> Inconsistent names: {'id', 'key'}\n\n// after\nclass A(NamedTuple):\n  id: int\n\nclass B(NamedTuple):\n  id: int","handlingStrategy":"validation","validationCode":"def check_same_field_names(types):\n    names = [set(t._fields) for t in types]\n    if any(n != names[0] for n in names):\n        raise TypeError(\"Union element types must share identical field names\")","typeGuard":"def same_field_names(types):\n    return bool(types) and all(getattr(t, '_fields', None) == getattr(types[0], '_fields', None) for t in types)","tryCatchPattern":"try:\n    schema = union_schema_type(element_types)\nexcept TypeError as e:\n    if \"Inconsistent names\" in str(e):\n        schema = named_tuple_from_schema(common_schema)  # explicit mapping\n    else:\n        raise","preventionTips":["Use identical field names across record types participating in a Union.","Centralize record type definitions in one module instead of duplicating them.","Validate union schemas in CI before deploying pipeline changes."],"tags":["python","apache-beam","schema","type-hints","union"],"backgroundTag":"schema-validation-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}