apache/beam · error · AttributeError
'%s' object has no attribute '%s'
Error message
'%s' object has no attribute '%s'
What it means
PipelineOptions.__getattr__ forwards attribute access to parsed option values; if the name is not among the visible options for this options class, AttributeError is raised. This means the option was never defined by this PipelineOptions subclass or was not parsed.
Source
Thrown at sdks/python/apache_beam/options/pipeline_options.py:704
return tuple(map(int, v1_parts)) < tuple(map(int, v2_parts))
def _visible_option_list(self) -> list[str]:
return sorted(
option for option in dir(self._visible_options) if option[0] != '_')
def __dir__(self) -> list[str]:
return sorted(
dir(type(self)) + list(self.__dict__) + self._visible_option_list())
def __getattr__(self, name):
# Special methods which may be accessed before the object is
# fully constructed (e.g. in unpickling).
if name[:2] == name[-2:] == '__':
return object.__getattribute__(self, name)
elif name in self._visible_option_list():
return self._all_options[name]
else:
raise AttributeError(
"'%s' object has no attribute '%s'" % (type(self).__name__, name))
def __setattr__(self, name, value):
if name in ('_flags', '_all_options', '_visible_options'):
super().__setattr__(name, value)
elif name in self._visible_option_list():
self._all_options[name] = value
else:
raise AttributeError(
"'%s' object has no attribute '%s'" % (type(self).__name__, name))
def __str__(self):
return '%s(%s)' % (
type(self).__name__,
', '.join(
'%s=%s' % (option, getattr(self, option))
for option in self._visible_option_list()))
View on GitHub (pinned to 12126d8942)
Solutions
- Use view_as with the correct options class that defines the attribute.
- Fix the attribute-name typo to match the option's getter name.
- Define custom options properly in a PipelineOptions subclass via class annotations.
Example fix
# before runner = options.project_id # wrong attribute on base class # after from apache_beam.options.pipeline_options import GoogleCloudOptions project_id = options.view_as(GoogleCloudOptions).project_id
Defensive patterns
Strategy: type-guard
Validate before calling
if not hasattr(options.view_as(GoogleCloudOptions), 'project_id'): ...
Type guard
def has_option(opts, name: str) -> bool:
return name in opts.get_all_options(drop_default=True) or hasattr(opts.view_as(type(opts)), name) Try / catch
try:
val = options.my_option
except AttributeError:
val = None # or use options.get_all_options() to inspect available keys Prevention
- Use view_as(ExactOptionsClass) and rely on typed getters instead of raw attributes.
- Inspect options.get_all_options() to discover valid option names.
- Register custom options via a PipelineOptions subclass.
When it happens
Trigger: Accessing options.some_flag where some_flag is not a registered option of the view class, e.g. options.view_as(GoogleCloudOptions).my_custom_option, or accessing an option before it exists during unpickling.
Common situations: Typo in the option name, reading an option from the wrong view class, or custom options added without a _add_ method/annotation on the subclass.
Understand the failure class
Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.
Related errors
- element not accessible in this context
- timestamp not accessible in this context
- windows not accessible in this context
- f"No inline provider found for {name}"
- Could not find coder for URN " + urn
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/35cdf6394abd87d7.
Report an issue: GitHub.