fix(super_component): only expose run_async when wrapped pipeline is AsyncPipeline#11194
Open
alvinttang wants to merge 1 commit intodeepset-ai:mainfrom
Open
Conversation
A SuperComponent wrapping a synchronous Pipeline used to advertise async
support because run_async was defined on the class. As a result:
- Calling run_async on such a SuperComponent raised
TypeError('Pipeline is not an AsyncPipeline. run_async is not supported.')
- Adding such a SuperComponent to an outer AsyncPipeline made the outer
pipeline route to run_async and crash with the same error, since
AsyncPipeline._run_component_async dispatches based on
__haystack_supports_async__.
run_async is now bound on the instance only when the wrapped pipeline is
an AsyncPipeline, so hasattr(super_component, 'run_async') and
__haystack_supports_async__ correctly reflect the wrapped pipeline.
Closes deepset-ai#9435
|
Someone is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
alvinttang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Member
|
Hi @alvinttang Thank you for opening this PR. We need you to agree to the CLA please. In particular, this commit was not done by a GitHub user: 73be582 Could you fix that please? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SuperComponentdeclaredasync def run_async(...)at the class level, soComponentMeta.__call__'s post-__init__hasattr(instance, \"run_async\")check set__haystack_supports_async__ = Truefor every instance — including those wrapping a syncPipeline. Two visible failures resulted:wrapper.run_async(...)on a sync-pipeline-backedSuperComponentraisedTypeError: Pipeline is not an AsyncPipeline....SuperComponentinside an outerAsyncPipelinemadeAsyncPipeline._run_component_asyncdispatch torun_async, and the whole outer pipeline crashed withPipelineRuntimeError.Fixes #9435
Fix
haystack/core/super_component/super_component.py:run_asyncto_run_async. The metaclass no longer sees a class-levelrun_asyncand therefore no longer marks everySuperComponentas async-capable.__init__bindsself.run_async = self._run_asyncper-instance only whenisinstance(pipeline, AsyncPipeline). Sync-pipeline-backed instances simply do not have arun_asyncattribute.TYPE_CHECKINGstub forrun_asyncso the static typing surface (used by the existing tests and downstream users) is preserved while the runtime attribute is bound lazily.Test
test/core/super_component/test_super_component.py:test_sync_pipeline_does_not_advertise_async_support—__haystack_supports_async__is False andrun_asyncattribute is absent.test_async_pipeline_advertises_async_support— positive control.test_super_component_with_sync_pipeline_inside_async_pipeline— the regression scenario, runsouter.run_async(...)and verifies it succeeds.All three RED before the patch, GREEN after. Existing tests
test_super_component_run_asyncandtest_super_component_async_serialization_deserializationstill pass.Locally on
darwin/arm64:pytest test/core/super_component/ test/core/component/→ 123 passed.test_pipeline_base.py(test_show_in_notebook,test_find_super_components,test_merge_super_component_pipelines) are unrelated and reproduce onmainwithout this patch.Risk notes
hasattr(super_component, \"run_async\")now returns False for sync-pipeline-backedSuperComponents. Any caller that previously hit the brokenrun_async(which always raisedTypeError) will now hitAttributeErrorinstead — strictly an improvement. The@super_componentdecorator path goes through_SuperComponent.__init__so it inherits the fix automatically.