{"record":{"id":"a5fe1bccd0714209","repo":"apache/beam","slug":"invalid-pattern-for-single-name-name-result-group-0","errorCode":null,"errorMessage":"Invalid pattern for single name: {name_result.group(0)}","messagePattern":"Invalid pattern for single name: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/internal/code_object_pickler.py","lineNumber":350,"sourceCode":"\ndef _get_code_object_from_single_name_pattern(\n    obj: types.ModuleType, name_result: re.Match[str], path: str):\n  \"\"\"Returns the code object from a name pattern.\n\n  Args:\n    obj: The object to search within.\n    name_result: The result of the name pattern search.\n    path: The path to the code object.\n\n  Returns:\n    The code object.\n\n  Raises:\n    ValueError: If the pattern is invalid.\n    AttributeError: If the code object is not found.\n  \"\"\"\n  if len(name_result.groups()) > 1:\n    raise ValueError(f'Invalid pattern for single name: {name_result.group(0)}')\n  # Groups are indexed starting at 1, group(0) is the entire match.\n  name = name_result.group(1)\n  if hasattr(obj, 'co_consts'):\n    for co_const in obj.co_consts:\n      if inspect.iscode(co_const) and co_const.co_name == name:\n        return co_const\n  raise AttributeError(f'Could not find code object with path: {path}')\n\n\ndef _get_code_object_from_lambda_with_args_pattern(\n    obj: types.ModuleType, lambda_with_args_result: re.Match[str], path: str):\n  \"\"\"Returns the code object from a lambda with args pattern.\n\n  Args:\n    obj: The object to search within.\n    lambda_with_args_result: The result of the lambda with args pattern search.\n    path: The path to the code object.\n","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/internal/code_object_pickler.py#L332-L368","documentation":"_get_code_object_from_single_name_pattern resolves a qual-name pattern expected to contain exactly one name group. If the regex match has more than one capture group, the pattern is not a 'single name' pattern and ValueError is raised, because the resolver only handles one name per step.","triggerScenarios":"get_code_from_identifier receiving a compound pattern (multiple parenthesized groups) — e.g. identifiers covering several nested names at once that should have been split into multiple resolution steps.","commonSituations":"Internally generated identifiers for deeply nested or dynamically defined callables; custom pickling code passing malformed identifier strings.","solutions":["Ensure identifiers are resolved one name-part at a time (split compound patterns before calling).","Define callables at module level to avoid compound qual-name patterns.","Catch ValueError and fall back to standard cloudpickle pickling.","If patterns are generated by Beam internals, update/patch apache_beam."],"exampleFix":"// before\nco = get_code_from_identifier(obj, 'outer.<locals>.inner.<locals>.deep')\n// after\nfor part in split_pattern('outer.<locals>.inner.<locals>.deep'):\n    co = get_code_from_identifier(co, part)","handlingStrategy":"try-catch","validationCode":"if identifier.count('<locals>') > 1 or '(' in identifier and identifier.count('(') > 1:\n    raise ValueError('identifier must resolve a single name per step')","typeGuard":"def is_single_name_pattern(match) -> bool:\n    return len(match.groups()) == 1","tryCatchPattern":"try:\n    co = get_code_from_identifier(obj, pattern)\nexcept ValueError as e:\n    if 'Invalid pattern for single name' in str(e):\n        co = resolve_step_by_step(obj, pattern)\n    else:\n        raise","preventionTips":["Resolve identifiers one name segment at a time.","Keep callables at module level so patterns stay simple.","Add unit tests for identifier resolution of nested functions."],"tags":["python","apache-beam","code-object","pickling"],"backgroundTag":"invalid-identifier-format","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}