haystack
haystack copied to clipboard
`_SuperComponent` always define `run_async` even when the underlying Pipeline is sync
Discovered in https://github.com/deepset-ai/haystack/pull/9420#pullrequestreview-2864343991
from haystack.components.preprocessors import DocumentPreprocessor
from haystack import Document
import asyncio
preprocessor = DocumentPreprocessor()
preprocessor.warm_up()
asyncio.run(preprocessor.run_async(documents=[Document(content="something")]))
Raises: TypeError: Pipeline is not an AsyncPipeline. run_async is not supported.
_SuperComponent defines a run_async method even when the underlying pipeline is synchronous. This leads to runtime errors and potentially confuses users, as the method appears available but always fails.
@anakin87 I see a few ways to solve this:
- Auto convert a Pipeline to AsyncPipeline under-the-hood if a user calls
run_asyncon a SuperComponent defined withPipeline. And I guess vice-versa if the opposite happens. - Consolidate our Pipeline and AsyncPipeline abstractions into one object? Not sure how easy this would be.
- Dynamically add the correct run method through the decorator? This approach wouldn't work with the inheritance approach creating generic SuperComponents when using
SuperComponentdirectly. - Leave as-is but throw an error at run time if a user tries to use
run_asyncbut defined their SuperComponent withPipeline
What do you think?