{"record":{"id":"573b048014e2f71f","repo":"apache/beam","slug":"dofn-restrictionparam-expected-restrictionprovider-object","errorCode":null,"errorMessage":"DoFn.RestrictionParam expected RestrictionProvider object.","messagePattern":"DoFn\\.RestrictionParam expected RestrictionProvider object\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/core.py","lineNumber":464,"sourceCode":"  def __eq__(self, other):\n    if type(self) == type(other):\n      return self.param_id == other.param_id\n    return False\n\n  def __hash__(self):\n    return hash(self.param_id)\n\n  def __repr__(self):\n    return self.param_id\n\n\nclass _RestrictionDoFnParam(_DoFnParam):\n  \"\"\"Restriction Provider DoFn parameter.\"\"\"\n  def __init__(self, restriction_provider=None):\n    # type: (typing.Optional[RestrictionProvider]) -> None\n    if (restriction_provider is not None and\n        not isinstance(restriction_provider, RestrictionProvider)):\n      raise ValueError(\n          'DoFn.RestrictionParam expected RestrictionProvider object.')\n    self.restriction_provider = restriction_provider\n    self.param_id = (\n        'RestrictionParam(%s)' % restriction_provider.__class__.__name__)\n\n\nclass _StateDoFnParam(_DoFnParam):\n  \"\"\"State DoFn parameter.\"\"\"\n  def __init__(self, state_spec):\n    # type: (StateSpec) -> None\n    if not isinstance(state_spec, StateSpec):\n      raise ValueError(\"DoFn.StateParam expected StateSpec object.\")\n    self.state_spec = state_spec\n    self.param_id = 'StateParam(%s)' % state_spec.name\n\n\nclass _TimerDoFnParam(_DoFnParam):\n  \"\"\"Timer DoFn parameter.\"\"\"","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/core.py#L446-L482","documentation":"ValueError raised by `_RestrictionDoFnParam.__init__` (exposed as `DoFn.RestrictionParam`) when the supplied restriction_provider is not `None` and is not an instance of `RestrictionProvider`. Only a real restriction provider (or None) is accepted.","triggerScenarios":"Writing `DoFn.RestrictionParam(MyDoFn)` or `DoFn.RestrictionParam(some_spec)` passing a DoFn, spec, class, or string instead of an object implementing `RestrictionProvider` (e.g. a `RangeTracker`-backed provider like those in `apache_beam.io.range_trackers` used with custom splittable DoFns).","commonSituations":"Confusing RestrictionParam with StateParam/TimerParam arguments; passing the provider class instead of an instance; custom splittable-DoFn boilerplate mistakes.","solutions":["Pass an object whose class subclasses `RestrictionProvider` (e.g. `OffsetRangeTracker`-based provider or a DoFn's `restriction_provider` implementation).","Pass `None` only if intentionally omitting the restriction.","Verify you didn't pass the provider's class rather than an instance."],"exampleFix":"// before\nparam = DoFn.RestrictionParam(MyRestrictionProviderClass)\n// after\nparam = DoFn.RestrictionParam(MyRestrictionProvider())  # instance of RestrictionProvider","handlingStrategy":"type-guard","validationCode":"from apache_beam.transforms.core import RestrictionProvider\nif restriction_provider is not None and not isinstance(restriction_provider, RestrictionProvider):\n    raise TypeError('expected RestrictionProvider instance')","typeGuard":"from apache_beam.transforms.core import RestrictionProvider\ndef is_restriction_provider(x) -> bool:\n    return x is None or isinstance(x, RestrictionProvider)","tryCatchPattern":"try:\n    param = DoFn.RestrictionParam(provider)\nexcept ValueError as e:\n    if 'RestrictionProvider' in str(e):\n        provider = provider() if isinstance(provider, type) else None","preventionTips":["Pass instances, not classes, to DoFn params","Subclass RestrictionProvider for custom splittable DoFns","Don't confuse RestrictionParam arguments with State/Timer specs"],"tags":["apache-beam","dofn","splittable-dofn","type-check"],"backgroundTag":"type-mismatch","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"}