fix: guard unsubscripted Variadic type in InputSocket#11493
Open
axelray-dev wants to merge 1 commit into
Open
Conversation
Bare Annotated[Iterable, HAYSTACK_VARIADIC_ANNOTATION] (no type argument) caused IndexError in get_args(...)[0] on line 100. Now checks that the inner Iterable has type args before unpacking, and raises ComponentError with a clear message when it does not. Fixes deepset-ai#11453
|
@axelray-dev is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
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.
What's broken
Instantiating a component with a bare
Annotated[Iterable, HAYSTACK_VARIADIC_ANNOTATION]annotation (no type argument) crashes withIndexError: tuple index out of rangeinInputSocket.__post_init__. The crash happens at component instantiation time, bypassing static type checking. For example:raises
IndexErrorinsideget_args(get_args(self.type)[0])[0]at line 100.Why it happens
get_args(Iterable)returns an empty tuple when the iterable has no type argument, so the unconditional[0]index fails.Fix
Replaced the bare double-index with a guarded version that checks whether
get_args()results are non-empty. When the inner type is unsubscripted, raisesComponentErrorwith a clear message: "Variadic input 'inputs' must have a type argument, e.g. Variadic[int]."Test
Added
test_input_socket_variadic_without_type_arg_raises_component_errorwhich creates a component with a bareAnnotated[Iterable, HAYSTACK_VARIADIC_ANNOTATION]input and asserts thatComponentErroris raised with the expected message.Fixes #11453
This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.