{"record":{"id":"480284613c11c191","repo":"apache/beam","slug":"initializing-sdfboundedsourcerestrictiontracker-requires-a","errorCode":null,"errorMessage":"Initializing SDFBoundedSourceRestrictionTracker requires a _SDFBoundedSourceRestriction. Got %s instead.","messagePattern":"Initializing SDFBoundedSourceRestrictionTracker requires a _SDFBoundedSourceRestriction\\. Got (.+?) instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/iobase.py","lineNumber":1805,"sourceCode":"                    split_pos,\n                    stop_pos)))\n    except Exception:\n      # For any exceptions from underlying trySplit calls, the wrapper will\n      # think that the source refuses to split at this point. In this case,\n      # no split happens at the wrapper level.\n      return None\n\n\nclass _SDFBoundedSourceRestrictionTracker(RestrictionTracker):\n  \"\"\"An `iobase.RestrictionTracker` implementations for wrapping BoundedSource\n  with SDF. The tracked restriction is a _SDFBoundedSourceRestriction, which\n  wraps SourceBundle and RangeTracker.\n\n  Delegated RangeTracker guarantees synchronization safety.\n  \"\"\"\n  def __init__(self, restriction):\n    if not isinstance(restriction, _SDFBoundedSourceRestriction):\n      raise ValueError(\n          'Initializing SDFBoundedSourceRestrictionTracker'\n          ' requires a _SDFBoundedSourceRestriction. Got %s instead.' %\n          restriction)\n    self.restriction = restriction\n\n  def current_progress(self) -> RestrictionProgress:\n    return RestrictionProgress(\n        fraction=self.restriction.range_tracker().fraction_consumed())\n\n  def current_restriction(self):\n    self.restriction.range_tracker()\n    return self.restriction\n\n  def start_pos(self):\n    return self.restriction.range_tracker().start_position()\n\n  def stop_pos(self):\n    return self.restriction.range_tracker().stop_position()","sourceCodeStart":1787,"sourceCodeEnd":1823,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/iobase.py#L1787-L1823","documentation":"SDFBoundedSourceRestrictionTracker.__init__ requires its restriction argument to be a _SDFBoundedSourceRestriction (the internal wrapper pairing a SourceBundle with a RangeTracker). Passing any other restriction type (e.g. a raw OffsetRange from ordinary SDF code) raises ValueError. This is an internal invariant for the legacy-BoundedSource-to-SDF adapter.","triggerScenarios":"Constructing SDFBoundedSourceRestrictionTracker directly with a non _SDFBoundedSourceRestriction object, or a custom restriction provider returning a foreign restriction type for a BoundedSource-based DoFn.","commonSituations":"Custom runners or testing harnesses instantiating the tracker manually; subclassing the provider and overriding initial_restriction with a different restriction type.","solutions":["Let Beam create the tracker via SDFBoundedSourceRestrictionProvider instead of constructing it manually.","If you must construct it, build the restriction via _SDFBoundedSourceRestriction(SourceBundle(...), RangeTracker...).","Do not override initial_restriction/split_restriction in a subclass with non-wrapper restriction types."],"exampleFix":"# before\nSDFBoundedSourceRestrictionTracker(OffsetRange(0, 100))\n# after\nrestriction = _SDFBoundedSourceRestriction(bundle, range_tracker)\nSDFBoundedSourceRestrictionTracker(restriction)","handlingStrategy":"type-guard","validationCode":"from apache_beam.io.iobase import _SDFBoundedSourceRestriction\nassert isinstance(restriction, _SDFBoundedSourceRestriction), type(restriction)","typeGuard":"def is_sdf_bounded_restriction(restriction) -> bool:\n    from apache_beam.io.iobase import _SDFBoundedSourceRestriction\n    return isinstance(restriction, _SDFBoundedSourceRestriction)","tryCatchPattern":"try:\n    tracker = SDFBoundedSourceRestrictionTracker(restriction)\nexcept ValueError as e:\n    log.error('Wrong restriction type %s', type(restriction))","preventionTips":["Do not instantiate internal restriction trackers directly","Use the provider's restriction-producing methods","Keep restriction types untouched when subclassing the provider"],"tags":["apache-beam","python","splittable-dofn","internal-invariant","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}