apache/beam · error · AttributeError
Could not find code object with path: {path}
Error message
Could not find code object with path: {path} What it means
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.
Source
Thrown at sdks/python/apache_beam/internal/code_object_pickler.py:357
name_result: The result of the name pattern search.
path: The path to the code object.
Returns:
The code object.
Raises:
ValueError: If the pattern is invalid.
AttributeError: If the code object is not found.
"""
if len(name_result.groups()) > 1:
raise ValueError(f'Invalid pattern for single name: {name_result.group(0)}')
# Groups are indexed starting at 1, group(0) is the entire match.
name = name_result.group(1)
if hasattr(obj, 'co_consts'):
for co_const in obj.co_consts:
if inspect.iscode(co_const) and co_const.co_name == name:
return co_const
raise AttributeError(f'Could not find code object with path: {path}')
def _get_code_object_from_lambda_with_args_pattern(
obj: types.ModuleType, lambda_with_args_result: re.Match[str], path: str):
"""Returns the code object from a lambda with args pattern.
Args:
obj: The object to search within.
lambda_with_args_result: The result of the lambda with args pattern search.
path: The path to the code object.
Returns:
The code object.
Raises:
AttributeError: If the code object is not found.
"""
name = lambda_with_args_result.group(1)View on GitHub (pinned to 12126d8942)
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.
Example fix
// before
get_code_from_identifier('mymodule.outer.<lambda>') # no nested code object named in co_consts
// after
# reference a real resolvable name instead
get_code_from_identifier('mymodule.outer') # or refactor helper to top-level: 'mymodule.helper' Defensive patterns
Strategy: type-guard
Validate before calling
import sys, inspect, types
def identifier_resolves(path):
parts = path.split('.')
obj = sys.modules.get(parts[0])
if obj is None: return False
for part in parts[1:]:
consts = getattr(obj, 'co_consts', None)
if consts is None or not any(inspect.iscode(c) and c.co_name == part for c in consts):
return False
return True Type guard
def is_resolvable_identifier(path) -> bool:
import sys
parts = path.split('.')
return bool(parts[0]) and parts[0] in sys.modules Try / catch
try:
code = get_code_from_identifier(path)
except AttributeError as e:
logger.error('Identifier %s does not resolve (module/worker version skew?): %s', path, e)
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- cannot check importability of {} instances
- Qual name parts too long
- Invalid pattern for single name: {name_result.group(0)}
- Path must not be empty.
- Module {parts[0]} not found in sys.modules
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/220e2e0da78c2f5d.
Report an issue: GitHub.