{"record":{"id":"5a6949ce37b9f596","repo":"apache/beam","slug":"error-applying-transform-identify-object-spec-exn","errorCode":null,"errorMessage":"Error applying transform {identify_object(spec)}: {exn}","messagePattern":"Error applying transform (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_transform.py","lineNumber":521,"sourceCode":"  if input_type == 'list':\n    inputs = tuple(inputs_dict.values())\n  elif input_type == 'map':\n    inputs = inputs_dict\n  else:\n    if len(inputs_dict) == 0:\n      inputs = scope.root\n    elif len(inputs_dict) == 1:\n      inputs = next(iter(inputs_dict.values()))\n    else:\n      inputs = inputs_dict\n  _LOGGER.info(\"Expanding %s \", identify_object(spec))\n  ptransform = scope.create_ptransform(spec, inputs_dict.values())\n  try:\n    # TODO: Move validation to construction?\n    with FullyQualifiedNamedTransform.with_filter('*'):\n      outputs = inputs | scope.unique_name(spec, ptransform) >> ptransform\n  except Exception as exn:\n    raise ValueError(\n        f\"Error applying transform {identify_object(spec)}: {exn}\") from exn\n\n  # Optional output_schema was found, so lets expand on that before returning.\n  if output_schema_spec:\n    error_handling_spec = {}\n    # Obtain original transform error_handling_spec, so that all validate\n    # schema errors use that.\n    if 'error_handling' in spec.get('config', None):\n      error_handling_spec = spec.get('config').get('error_handling', {})\n\n    outputs = expand_output_schema_transform(\n        spec=output_schema_spec,\n        outputs=outputs,\n        error_handling_spec=error_handling_spec)\n\n  if isinstance(outputs, dict):\n    # TODO: Handle (or at least reject) nested case.\n    return outputs","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_transform.py#L503-L539","documentation":"expand_leaf_transform wraps any exception raised while applying a leaf PTransform (during construction/expand) into a ValueError prefixed with 'Error applying transform' and the transform's identified location. Beam does this to attribute generic transform failures back to the specific YAML spec that caused them.","triggerScenarios":"scope.create_ptransform(spec, inputs) or the `inputs | name >> ptransform` application raises — e.g. invalid config for the transform type, missing required config field, wrong input schema, or any exception thrown inside the underlying PTransform's expand().","commonSituations":"Misconfigured built-in transforms (bad path in ReadFromText, wrong field names in MapToFields), schema mismatches between chained transforms, or provider/transform constructor errors surfaced through YAML.","solutions":["Read the chained inner exception (caused by) — the fix is almost always in the original exn message, not this wrapper.","Validate the transform's 'config' against the transform's documented schema before running the pipeline.","Check that input PCollections have the schema/fields the transform expects.","Use ValidateWithSchema or --dry-run style validation to catch config problems early."],"exampleFix":"// before (YAML)\n- type: MapToFields\n  input: rows\n  config:\n    total: price * quantity_typo\n// after\n- type: MapToFields\n  input: rows\n  config:\n    total: price * quantity","handlingStrategy":"try-catch","validationCode":"def check_transform_config(spec, known):\n    t = spec.get('type')\n    if t not in known:\n        raise ValueError(f'Unknown transform type {t}')\n    missing = set(known[t].get('required', [])) - set(spec.get('config', {}))\n    if missing:\n        raise ValueError(f'{t} missing config keys: {missing}')","typeGuard":"def is_valid_config(spec) -> bool:\n    return isinstance(spec.get('config', {}), dict)","tryCatchPattern":"try:\n    pipeline.run()\nexcept ValueError as e:\n    if e.__cause__ is not None:\n        print(f\"Root cause: {e.__cause__}\")\n    raise","preventionTips":["Always inspect the __cause__ chain; this error is a wrapper.","Test transforms in isolation with small sample inputs before full pipelines.","Keep configs matched to the transform's documented schema."],"tags":["python","apache-beam","yaml","transform"],"backgroundTag":"invalid-config-value","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"}