{"record":{"id":"3e5be3ce081ade56","repo":"apache/beam","slug":"initialize-restrictiontrackerview-requires","errorCode":null,"errorMessage":"Initialize RestrictionTrackerView requires ThreadsafeRestrictionTracker.","messagePattern":"Initialize RestrictionTrackerView requires ThreadsafeRestrictionTracker\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/sdf_utils.py","lineNumber":162,"sourceCode":"\n  def is_bounded(self):\n    return self._restriction_tracker.is_bounded()\n\n\nclass RestrictionTrackerView(object):\n  \"\"\"A DoFn view of thread-safe RestrictionTracker.\n\n  The RestrictionTrackerView wraps a ThreadsafeRestrictionTracker and only\n  exposes APIs that will be called by a ``DoFn.process()``. During execution\n  time, the RestrictionTrackerView will be fed into the ``DoFn.process`` as a\n  restriction_tracker.\n  \"\"\"\n  def __init__(\n      self,\n      threadsafe_restriction_tracker: ThreadsafeRestrictionTracker) -> None:\n    if not isinstance(threadsafe_restriction_tracker,\n                      ThreadsafeRestrictionTracker):\n      raise ValueError(\n          'Initialize RestrictionTrackerView requires '\n          'ThreadsafeRestrictionTracker.')\n    self._threadsafe_restriction_tracker = threadsafe_restriction_tracker\n\n  def current_restriction(self):\n    return self._threadsafe_restriction_tracker.current_restriction()\n\n  def try_claim(self, position):\n    return self._threadsafe_restriction_tracker.try_claim(position)\n\n  def defer_remainder(self, deferred_time=None):\n    self._threadsafe_restriction_tracker.defer_remainder(deferred_time)\n\n  def is_bounded(self):\n    self._threadsafe_restriction_tracker.is_bounded()\n\n\nclass ThreadsafeWatermarkEstimator(object):","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/sdf_utils.py#L144-L180","documentation":"RestrictionTrackerView is a read-only view over a ThreadsafeRestrictionTracker for splittable DoFn size/watermark reporting. Its constructor type-checks the argument and raises this ValueError if it is not a ThreadsafeRestrictionTracker instance.","triggerScenarios":"Instantiating RestrictionTrackerView(tracker) with a plain RestrictionTracker (not wrapped in ThreadsafeRestrictionTracker), None, or any other tracker type.","commonSituations":"Implementing a custom splittable DoFn's restriction_tracker() method and returning the raw tracker instead of the threadsafe wrapper required by the framework.","solutions":["Wrap the tracker in ThreadsafeRestrictionTracker first, then pass it to RestrictionTrackerView","Ensure your DoFn creates the threadsafe wrapper once and derives the view from it"],"exampleFix":"// before\nreturn RestrictionTrackerView(OffsetRangeTracker(self._range))\n// after\nself._tracker = ThreadsafeRestrictionTracker(OffsetRangeTracker(self._range))\nreturn RestrictionTrackerView(self._tracker)","handlingStrategy":"type-guard","validationCode":"isinstance(t, ThreadsafeRestrictionTracker)  # check before constructing view","typeGuard":"from apache_beam.runners.sdf_utils import ThreadsafeRestrictionTracker\ndef is_threadsafe_tracker(x) -> bool:\n    return isinstance(x, ThreadsafeRestrictionTracker)","tryCatchPattern":"try:\n    view = RestrictionTrackerView(t)\nexcept ValueError as e:\n    if 'ThreadsafeRestrictionTracker' in str(e):\n        t = ThreadsafeRestrictionTracker(t._restriction_tracker)  # or rebuild\n        view = RestrictionTrackerView(t)\n    else:\n        raise","preventionTips":["Always create ThreadsafeRestrictionTracker before the view","Store the threadsafe tracker on self and derive the view from it","Follow the sdf_utils wrapper pattern in custom SDFs"],"tags":["apache-beam","sdf","type-mismatch","restriction-tracker"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}