apache/beam · error · ValueError
Path must not be empty.
Error message
Path must not be empty.
What it means
get_code_from_identifier validates that the identifier string is non-empty before splitting on dots. An empty (or falsy) identifier is rejected with ValueError 'Path must not be empty.' This guards upstream callers (_make_function_from_identifier) from passing uninitialized path data.
Source
Thrown at sdks/python/apache_beam/internal/code_object_pickler.py:436
return obj_
raise AttributeError(f'Could not find code object with path: {path}')
def get_code_from_identifier(code_object_identifier: str):
"""Returns the code object corresponding to the code object identifier.
Args:
code_object_identifier: A string representing the code object identifier.
Returns:
The code object.
Raises:
ValueError: If the path is empty or invalid.
AttributeError: If the attribute is not found.
"""
if not code_object_identifier:
raise ValueError('Path must not be empty.')
parts = code_object_identifier.split('.')
if parts[0] not in sys.modules:
raise AttributeError(f'Module {parts[0]} not found in sys.modules')
obj = sys.modules[parts[0]]
for part in parts[1:]:
if name_result := _SINGLE_NAME_PATTERN.fullmatch(part):
obj = _get_code_object_from_single_name_pattern(
obj, name_result, code_object_identifier)
elif lambda_with_args_result := _LAMBDA_WITH_ARGS_PATTERN.fullmatch(part):
obj = _get_code_object_from_lambda_with_args_pattern(
obj, lambda_with_args_result, code_object_identifier)
elif lambda_with_hash_result := _LAMBDA_WITH_HASH_PATTERN.fullmatch(part):
obj = _get_code_object_from_lambda_with_hash_pattern(
obj, lambda_with_hash_result, code_object_identifier)
elif default_result := _DEFAULT_PATTERN.fullmatch(part):
index = int(default_result.group(2))
if index >= len(obj.__defaults__):
raise ValueError(View on GitHub (pinned to 12126d8942)
Solutions
- Check the identifier is non-empty before calling; fix the code that produced the empty string.
- Guard with `if identifier:` and skip/fail fast with context about where it came from.
- Inspect the pickling source that generated the reference to see why the name was blank.
Example fix
// before
fn = _make_function_from_identifier(identifier) # identifier == ''
// after
if not identifier:
raise ValueError(f'Cannot unpickle function: empty identifier from {ctx}')
fn = _make_function_from_identifier(identifier) Defensive patterns
Strategy: validation
Validate before calling
def ensure_nonempty(path):
if not path:
raise ValueError('code object identifier is empty; upstream pickling produced no name')
return path Type guard
def is_valid_identifier(path) -> bool:
return isinstance(path, str) and bool(path.strip()) Try / catch
try:
fn = _make_function_from_identifier(ident)
except ValueError as e:
raise RuntimeError(f'Blank function identifier from serialized reference: {e}') from e Prevention
- Validate serialized payloads contain the identifier field before unpickling.
- Never build paths via unchecked string concatenation.
- Log provenance of identifiers to debug blank-name sources.
When it happens
Trigger: Calling get_code_from_identifier('') directly, or _make_function_from_identifier receiving an empty/None code-object identifier, typically from an empty attribute name extracted during pickling or a corrupted/blank serialized reference.
Common situations: A pickled payload missing the identifier field; code that builds the path via string concatenation ending up empty; reading function names from metadata that failed to populate.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- cannot check importability of {} instances
- Qual name parts too long
- Invalid pattern for single name: {name_result.group(0)}
- Could not find code object with path: {path}
- Module {parts[0]} not found in sys.modules
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/074b6d8c2cc66b92.
Report an issue: GitHub.