mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-12-25 14:08:27 +00:00
fix: In set_output_types check that the decorator @component.output_types is not present on the run_async method (#9485)
* Fix * Add reno
This commit is contained in:
parent
1e2214a1a0
commit
ff56363db1
@ -512,13 +512,18 @@ class _Component:
|
||||
# no decorators here
|
||||
def run(self, value: int):
|
||||
return {"output_1": 1, "output_2": "2"}
|
||||
|
||||
# also no decorators here
|
||||
async def run_async(self, value: int):
|
||||
return {"output_1": 1, "output_2": "2"}
|
||||
```
|
||||
"""
|
||||
has_decorator = hasattr(instance.run, "_output_types_cache")
|
||||
if has_decorator:
|
||||
has_run_decorator = hasattr(instance.run, "_output_types_cache")
|
||||
has_run_async_decorator = hasattr(instance, "run_async") and hasattr(instance.run_async, "_output_types_cache")
|
||||
if has_run_decorator or has_run_async_decorator:
|
||||
raise ComponentError(
|
||||
"Cannot call `set_output_types` on a component that already has "
|
||||
"the 'output_types' decorator on its `run` method"
|
||||
"Cannot call `set_output_types` on a component that already has the 'output_types' decorator on its "
|
||||
"`run` or `run_async` methods."
|
||||
)
|
||||
|
||||
instance.__haystack_output__ = Sockets(
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
When calling `set_output_types` we now also check that the decorator @component.output_types is not present on the `run_async` method of a Component. Previously we only checked that the Component.run method did not possess the decorator.
|
||||
@ -328,6 +328,23 @@ def test_output_types_decorator_and_set_output_types():
|
||||
_ = MockComponent()
|
||||
|
||||
|
||||
def test_output_types_decorator_and_set_output_types_async():
|
||||
@component
|
||||
class MockComponent:
|
||||
def __init__(self) -> None:
|
||||
component.set_output_types(self, value=int)
|
||||
|
||||
def run(self, value: int):
|
||||
return {"value": 1}
|
||||
|
||||
@component.output_types(value=int)
|
||||
async def run_async(self, value: int):
|
||||
return {"value": 1}
|
||||
|
||||
with pytest.raises(ComponentError, match="Cannot call `set_output_types`"):
|
||||
_ = MockComponent()
|
||||
|
||||
|
||||
def test_output_types_decorator_mismatch_run_async_run():
|
||||
@component
|
||||
class MockComponent:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user