From 28277a6b19b1574b908843d15df8f0013d16c6bd Mon Sep 17 00:00:00 2001 From: Ivan Danov Date: Mon, 15 Apr 2024 12:09:50 +0100 Subject: [PATCH] Add a test for transcoding loops of 1 or more nodes (#3810) Signed-off-by: Ivan Danov --- kedro/pipeline/pipeline.py | 3 ++- .../test_pipeline_with_transcoding.py | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/kedro/pipeline/pipeline.py b/kedro/pipeline/pipeline.py index 29d647b387..5a0d63b4cf 100644 --- a/kedro/pipeline/pipeline.py +++ b/kedro/pipeline/pipeline.py @@ -171,7 +171,8 @@ def __init__( try: self._toposorter.prepare() except CycleError as exc: - message = f"Circular dependencies exist among these items: {exc.args[1]}" + loop = list(set(exc.args[1])) + message = f"Circular dependencies exist among the following {len(loop)} item(s): {loop}" raise CircularDependencyError(message) from exc self._toposorted_nodes: list[Node] = [] diff --git a/tests/pipeline/test_pipeline_with_transcoding.py b/tests/pipeline/test_pipeline_with_transcoding.py index c8dc87441a..7e4ad04056 100644 --- a/tests/pipeline/test_pipeline_with_transcoding.py +++ b/tests/pipeline/test_pipeline_with_transcoding.py @@ -5,7 +5,11 @@ import kedro from kedro.pipeline import node from kedro.pipeline.modular_pipeline import pipeline as modular_pipeline -from kedro.pipeline.pipeline import OutputNotUniqueError, _strip_transcoding +from kedro.pipeline.pipeline import ( + CircularDependencyError, + OutputNotUniqueError, + _strip_transcoding, +) # Different dummy func based on the number of arguments @@ -177,6 +181,24 @@ def test_duplicates_in_transcoded_outputs(self): ] ) + def test_transcoding_loop(self): + with pytest.raises(CircularDependencyError, match="node1"): + modular_pipeline( + [ + node(identity, "A@pandas", "B@pandas", name="node1"), + node(identity, "B@spark", "C@spark", name="node2"), + node(identity, "C@spark", "A@spark", name="node3"), + ] + ) + + def test_transcoding_self_reference(self): + with pytest.raises(CircularDependencyError, match="node1"): + modular_pipeline( + [ + node(identity, "A@pandas", "A@spark", name="node1"), + ] + ) + class TestComplexPipelineWithTranscoding: """