{"record":{"id":"8a78ab2f94c71a28","repo":"apache/beam","slug":"sdfboundedsourcerestrictionprovider-can-only-utilize","errorCode":null,"errorMessage":"SDFBoundedSourceRestrictionProvider can only utilize BoundedSource","messagePattern":"SDFBoundedSourceRestrictionProvider can only utilize BoundedSource","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/iobase.py","lineNumber":1864,"sourceCode":"        restriction._source_bundle.start_position,\n        restriction._source_bundle.stop_position))\n\n\nclass _SDFBoundedSourceRestrictionProvider(core.RestrictionProvider):\n  \"\"\"\n  A `RestrictionProvider` that is used by SDF for `BoundedSource`.\n\n  This restriction provider initializes restriction based on input\n  element that is expected to be of BoundedSource type.\n  \"\"\"\n  def __init__(self, desired_chunk_size=None, restriction_coder=None):\n    self._desired_chunk_size = desired_chunk_size\n    self._restriction_coder = (\n        restriction_coder or _SDFBoundedSourceWrapperRestrictionCoder())\n\n  def _check_source(self, src):\n    if not isinstance(src, BoundedSource):\n      raise RuntimeError(\n          'SDFBoundedSourceRestrictionProvider can only utilize BoundedSource')\n\n  def initial_restriction(self, element_source: BoundedSource):\n    self._check_source(element_source)\n    range_tracker = element_source.get_range_tracker(None, None)\n    return _SDFBoundedSourceRestriction(\n        SourceBundle(\n            None,\n            element_source,\n            range_tracker.start_position(),\n            range_tracker.stop_position()))\n\n  def create_tracker(self, restriction):\n    return _SDFBoundedSourceRestrictionTracker(restriction)\n\n  def split(self, element, restriction):\n    if self._desired_chunk_size is None:\n      try:","sourceCodeStart":1846,"sourceCodeEnd":1882,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/iobase.py#L1846-L1882","documentation":"SDFBoundedSourceRestrictionProvider adapts legacy BoundedSources to the splittable-DoFn model and can therefore only operate on BoundedSource elements. _check_source raises RuntimeError when the element source is not a BoundedSource instance. This fails fast in initial_restriction and related restriction-provider methods.","triggerScenarios":"Using a DoFn that declares the restriction provider (via _check_source path) but receives a plain callable, a custom Source (non-BoundedSource), or any other object in place of a BoundedSource.","commonSituations":"Migrating old custom sources to SDF and wiring a non-BoundedSource class; passing a file pattern or config object instead of the constructed BoundedSource; Beam-internal callers processing element payloads of the wrong type after deserialization.","solutions":["Make the element passed to the DoFn an instance of apache_beam.io.iobase.BoundedSource.","Implement BoundedSource methods (estimate_size, split, read, get_range_tracker) on your custom source class.","Use the built-in FileBasedSource/RangeSource helpers, which are already BoundedSources.","If wrapping an existing Source, convert it into a BoundedSource implementation."],"exampleFix":"# before\n| beam.ParDo(MySdfDoFn(), 'not-a-source')\n# after\n| beam.ParDo(MySdfDoFn(), MyBoundedSource(file_pattern))","handlingStrategy":"type-guard","validationCode":"from apache_beam.io.iobase import BoundedSource\nassert isinstance(element_source, BoundedSource), type(element_source)","typeGuard":"def is_bounded_source(src) -> bool:\n    from apache_beam.io.iobase import BoundedSource\n    return isinstance(src, BoundedSource)","tryCatchPattern":"try:\n    restriction = provider.initial_restriction(element_source)\nexcept RuntimeError as e:\n    if 'BoundedSource' in str(e): log.error('%s is not a BoundedSource', type(element_source))","preventionTips":["Ensure SDF DoFn elements are BoundedSource instances","Subclass FileBasedSource/RangeSource for custom sources","Add isinstance assertions before handing sources to SDF pipelines"],"tags":["apache-beam","python","splittable-dofn","boundedsource","type-mismatch"],"backgroundTag":"incompatible-source-type","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"}