Skip to content

Commit 0e349f8

Browse files
committed
We still need to raise error if components do not have at least one of the two methods implemented
1 parent b2a750a commit 0e349f8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/neo4j_graphrag/experimental/pipeline/component.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ def __new__(
3737
# extract required inputs and outputs from the run method signature
3838
run_method = attrs.get("run")
3939
run_context_method = attrs.get("run_with_context")
40-
run = run_context_method or run_method
40+
run = run_context_method if run_context_method is not None else run_method
41+
if run is None:
42+
raise RuntimeError(
43+
f"You must implement either `run` or `run_with_context` in Component '{name}'"
44+
)
4145
sig = inspect.signature(run)
4246
attrs["component_inputs"] = {
4347
param.name: {

tests/unit/experimental/pipeline/test_component.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import pytest
1818

19+
from neo4j_graphrag.experimental.pipeline import Component
1920
from neo4j_graphrag.experimental.pipeline.types.context import RunContext
2021
from .components import ComponentMultiply, ComponentMultiplyWithContext, IntResultModel
2122

@@ -73,3 +74,16 @@ async def test_component_run_with_context() -> None:
7374
)
7475
assert result.result == 2
7576
notifier_mock.assert_awaited_once()
77+
78+
79+
def test_component_missing_method() -> None:
80+
with pytest.raises(RuntimeError) as e:
81+
82+
class WrongComponent(Component):
83+
# we must have either run or run_with_context
84+
pass
85+
86+
assert (
87+
"You must implement either `run` or `run_with_context` in Component 'WrongComponent'"
88+
in str(e)
89+
)

0 commit comments

Comments
 (0)