{"record":{"id":"6addf72eda8cbdf9","repo":"apache/beam","slug":"no-types-found-for-field-s","errorCode":null,"errorMessage":"No types found for field %s","messagePattern":"No types found for field (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/core.py","lineNumber":4249,"sourceCode":"      row_dict = row.as_dict()\n      for field in first_fields:\n        field_types_by_field[field].add(\n            trivial_inference.instance_to_type(row_dict.get(field)))\n\n    # Determine the appropriate type for each field\n    final_fields = []\n    for field in first_fields:\n      field_types = field_types_by_field[field]\n      non_none_types = {t for t in field_types if t is not type(None)}\n\n      if len(non_none_types) > 1:\n        final_type = typehints.Union[tuple(non_none_types)]\n      elif len(non_none_types) == 1 and len(field_types) == 1:\n        final_type = non_none_types.pop()\n      elif len(non_none_types) == 1 and len(field_types) == 2:\n        final_type = typehints.Optional[non_none_types.pop()]\n      else:\n        raise TypeError(\"No types found for field %s\", field)\n\n      final_fields.append((field, final_type))\n\n    return row_type.RowTypeConstraint.from_fields(final_fields)\n\n  def get_output_type(self):\n    return (\n        self.get_type_hints().simple_output_type(self.label) or\n        self.infer_output_type(None))\n\n  def expand(self, pbegin):\n    assert isinstance(pbegin, pvalue.PBegin)\n    serialized_values = [self._coder.encode(v) for v in self.values]\n    reshuffle = self.reshuffle\n\n    # Avoid the \"redistributing\" reshuffle for 0 and 1 element Creates.\n    # These special cases are often used in building up more complex\n    # transforms (e.g. Write).","sourceCodeStart":4231,"sourceCodeEnd":4267,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/core.py#L4231-L4267","documentation":"Raised while inferring the schema row type of a field when no usable non-None type could be computed from the union of candidate field types. Beam builds a RowTypeConstraint from schema fields; if the field's combined type hints collapse to nothing usable (e.g. all types are None), it cannot produce a final type and throws TypeError. This indicates the annotated schema types for the field are invalid or empty.","triggerScenarios":"Calling schema inference (e.g. via core.py's schema type inference at core.py:4249) on a class/field where the merged field_types contain no non-None types and no single-type case applies — e.g. a field annotated only with None or with types that all reduce to NoneType.","commonSituations":"Using @beam.Row or dataclass schema inference with a field whose type hint is missing/None; passing Optional-only annotations in unsupported combinations; version changes in Beam's type inference handling of Optional/Union fields.","solutions":["Add an explicit, non-None type annotation to the offending field (e.g. field: str).","If the field is truly optional, annotate as Optional[T] with a concrete T so inference yields typehints.Optional[T].","Remove NoneType-only entries from Unions on schema fields; keep at least one concrete type.","Pass an explicit schema/row type via with_output_types or a user_type instead of relying on inference."],"exampleFix":"// before\nclass Event:\n    def __init__(self, id):\n        self.id = None  # no type info\n// after\nclass Event:\n    def __init__(self, id: str):\n        self.id = id","handlingStrategy":"type-guard","validationCode":"import typing\nfor name, hint in typing.get_type_hints(MyClass).items():\n    assert hint is not None and hint is not type(None), f'field {name} lacks a concrete type'\nassert len(typing.get_args(hint)) > 0 or hint is not type(None)","typeGuard":"def has_concrete_hint(hint) -> bool:\n    import typing\n    return hint is not None and hint is not type(None) and (\n        not typing.get_origin(hint) == typing.Union or\n        any(a is not type(None) for a in typing.get_args(hint)))","tryCatchPattern":"try:\n    row_type = beam.RowTypeConstraint.from_user_type(MyClass)\nexcept TypeError as e:\n    if 'No types found for field' in str(e):\n        add_explicit_schema(MyClass)\n    else:\n        raise","preventionTips":["Annotate every schema field with a concrete type","Prefer Optional[T] over bare None fields","Run schema inference on classes in unit tests","Pass explicit user_type schemas for complex fields"],"tags":["apache-beam","python","type-inference","schema"],"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"}