{"record":{"id":"220e2e0da78c2f5d","repo":"apache/beam","slug":"could-not-find-code-object-with-path-path","errorCode":null,"errorMessage":"Could not find code object with path: {path}","messagePattern":"Could not find code object with path: (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/internal/code_object_pickler.py","lineNumber":357,"sourceCode":"    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\n  Returns:\n    The code object.\n\n  Raises:\n    AttributeError: If the code object is not found.\n  \"\"\"\n  name = lambda_with_args_result.group(1)","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/internal/code_object_pickler.py#L339-L375","documentation":"apache_beam's code_object_pickler serializes functions by identifier; _get_code_object_from_single_name_pattern walks an object's nested code constants (co_consts) looking for a nested function/code object whose co_name matches the final path component. When no matching nested code object exists it raises AttributeError with the full path. This means the dotted identifier does not resolve to a real code object in the module.","triggerScenarios":"Calling get_code_from_identifier (via _make_function_from_identifier during Beam pickling) with an identifier like 'mymodule.outer.<name>' where <name> is not a nested function/class of 'outer' at the version of the code actually loaded — e.g. the module on the worker differs from the one that created the identifier, or the name was renamed.","commonSituations":"Code version skew between job-submission environment and worker (stale .pyc or different package version on the cluster); renaming a nested helper without re-generating the identifier; hand-constructed identifiers for testing; __main__ vs installed-module mismatch in interactive/notebook runs.","solutions":["Verify the module imported on the runner actually contains the nested function named in the path (inspect the co_consts of the parent object).","Re-pin the Beam/dependency version so submission and worker use identical module code.","Regenerate the identifier from the current source instead of a stale one (re-run the pickling pipeline step).","Refactor the nested function to a module-level function so it is referenced by name directly rather than through co_consts traversal."],"exampleFix":"// before\nget_code_from_identifier('mymodule.outer.<lambda>')  # no nested code object named in co_consts\n// after\n# reference a real resolvable name instead\nget_code_from_identifier('mymodule.outer')  # or refactor helper to top-level: 'mymodule.helper'","handlingStrategy":"type-guard","validationCode":"import sys, inspect, types\ndef identifier_resolves(path):\n    parts = path.split('.')\n    obj = sys.modules.get(parts[0])\n    if obj is None: return False\n    for part in parts[1:]:\n        consts = getattr(obj, 'co_consts', None)\n        if consts is None or not any(inspect.iscode(c) and c.co_name == part for c in consts):\n            return False\n    return True","typeGuard":"def is_resolvable_identifier(path) -> bool:\n    import sys\n    parts = path.split('.')\n    return bool(parts[0]) and parts[0] in sys.modules","tryCatchPattern":"try:\n    code = get_code_from_identifier(path)\nexcept AttributeError as e:\n    logger.error('Identifier %s does not resolve (module/worker version skew?): %s', path, e)\n    raise","preventionTips":["Pin identical dependency and code versions on driver and workers.","Avoid referencing nested functions/lambdas across serialization boundaries; use module-level functions.","Regenerate identifiers after any source change."],"tags":["python","apache-beam","pickling","attribute-not-found"],"backgroundTag":"entity-not-found","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"}