{"record":{"id":"47526983749210fd","repo":"apache/beam","slug":"s-get-not-called-from-a-runtime-context","errorCode":null,"errorMessage":"%s.get() not called from a runtime context","messagePattern":"(.+?)\\.get\\(\\) not called from a runtime context","errorType":"exception","errorClass":"RuntimeValueProviderError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/options/value_provider.py","lineNumber":120,"sourceCode":"    self.value_type = value_type\n\n  def is_accessible(self):\n    return RuntimeValueProvider.runtime_options is not None\n\n  @classmethod\n  def get_value(cls, option_name, value_type, default_value):\n    if not RuntimeValueProvider.runtime_options:\n      return default_value\n\n    candidate = RuntimeValueProvider.runtime_options.get(option_name)\n    if candidate:\n      return value_type(candidate)\n    else:\n      return default_value\n\n  def get(self):\n    if RuntimeValueProvider.runtime_options is None:\n      raise error.RuntimeValueProviderError(\n          '%s.get() not called from a runtime context' % self)\n\n    return RuntimeValueProvider.get_value(\n        self.option_name, self.value_type, self.default_value)\n\n  @classmethod\n  def set_runtime_options(cls, pipeline_options):\n    RuntimeValueProvider.runtime_options = pipeline_options\n    RuntimeValueProvider.experiments = RuntimeValueProvider.get_value(\n        'experiments', set, set())\n\n  def __str__(self):\n    return '%s(option: %s, type: %s, default_value: %s)' % (\n        self.__class__.__name__,\n        self.option_name,\n        self.value_type.__name__,\n        repr(self.default_value))\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/options/value_provider.py#L102-L138","documentation":"RuntimeValueProvider.get() only works at pipeline runtime when runtime options have been set. Calling it at graph-construction time (before the pipeline runs) raises RuntimeValueProviderError because the actual value is not yet known.","triggerScenarios":"Calling value_provider.get() on a RuntimeValueProvider in the main program before Pipeline.run(); accessing .get() in a DoFn setup-free path where runtime options weren't populated (e.g. running without Dataflow template context).","commonSituations":"Reading option values during pipeline construction; using RuntimeValueProvider in DirectRunner runs without passing pipeline options at execution time; calling get() in tests.","solutions":["Only call get() inside worker-time code (DoFn.process) after runtime options are set","Check value_provider.is_accessible() before calling get() and provide a default otherwise","Use StaticValueProvider for values known at construction time","Pass required options at runtime (e.g. --my_option=value) so the provider becomes accessible"],"exampleFix":"// before\nname = beam_options.view_as(MyOptions).name.get()  # at graph build time\n// after\nname = beam_options.view_as(MyOptions).name  # pass the provider; call .get() inside DoFn.process, guarded by is_accessible()","handlingStrategy":"type-guard","validationCode":"if not vp.is_accessible():\n    raise RuntimeError('option not available yet; run at pipeline runtime')","typeGuard":"def is_readable(vp):\n    return vp.is_accessible()","tryCatchPattern":"try:\n    value = vp.get()\nexcept RuntimeValueProviderError:\n    value = default_value","preventionTips":["Only call get() inside DoFn.process or after pipeline start","Prefer StaticValueProvider for build-time-known values","Always provide defaults for options","Never dereference RuntimeValueProvider during graph construction"],"tags":["python","apache-beam","value-provider","runtime-context"],"backgroundTag":"missing-env-var","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}