@@ -371,42 +371,30 @@ def _is_stream_done(self, stream_name: str) -> bool:
371371 return stream_name in self ._streams_done
372372
373373 def _collect_all_parent_stream_names (self , stream_name : str ) -> Set [str ]:
374- """
375- Recursively collect all parent stream names for a given stream.
376- For example, if we have: epics -> issues -> comments
377- Then for comments, this returns {issues, epics}
374+ """Recursively collect all parent stream names for a given stream.
378375
379- :param stream_name: The stream to collect parents for
380- :return: Set of all parent stream names (recursively)
376+ For example, if we have: epics -> issues -> comments
377+ Then for comments, this returns {issues, epics}.
381378 """
379+ from airbyte_cdk .sources .declarative .partition_routers .substream_partition_router import (
380+ SubstreamPartitionRouter ,
381+ )
382+ from airbyte_cdk .sources .streams .concurrent .default_stream import DefaultStream
383+
382384 parent_names : Set [str ] = set ()
383385 stream = self ._stream_name_to_instance .get (stream_name )
384386
385387 if not stream :
386388 return parent_names
387389
388- # Get partition router if it exists (this is where parent streams are defined)
389- partition_router = None
390-
391- # Try DefaultStream path first (_stream_partition_generator._stream_slicer._partition_router)
392- if (
393- hasattr (stream , "_stream_partition_generator" )
394- and hasattr (stream ._stream_partition_generator , "_stream_slicer" )
395- and hasattr (stream ._stream_partition_generator ._stream_slicer , "_partition_router" )
396- ):
397- partition_router = stream ._stream_partition_generator ._stream_slicer ._partition_router
398- # Fallback to legacy path (retriever.partition_router) for backward compatibility and test mocks
399- elif hasattr (stream , "retriever" ) and hasattr (stream .retriever , "partition_router" ):
400- partition_router = stream .retriever .partition_router
390+ partition_router = (
391+ stream .get_partition_router () if isinstance (stream , DefaultStream ) else None
392+ )
401393
402- # SubstreamPartitionRouter has parent_stream_configs
403- if partition_router and hasattr (partition_router , "parent_stream_configs" ):
394+ if isinstance (partition_router , SubstreamPartitionRouter ):
404395 for parent_config in partition_router .parent_stream_configs :
405- parent_stream = parent_config .stream
406- parent_name = parent_stream .name
396+ parent_name = parent_config .stream .name
407397 parent_names .add (parent_name )
408-
409- # Recursively collect grandparents, great-grandparents, etc.
410398 parent_names .update (self ._collect_all_parent_stream_names (parent_name ))
411399
412400 return parent_names
0 commit comments