Skip to content

fix: guard unsubscripted Variadic type in InputSocket#11493

Merged
sjrl merged 2 commits into
deepset-ai:mainfrom
axelray-dev:fix/variadic-unsubscripted-indexerror
Jun 18, 2026
Merged

fix: guard unsubscripted Variadic type in InputSocket#11493
sjrl merged 2 commits into
deepset-ai:mainfrom
axelray-dev:fix/variadic-unsubscripted-indexerror

Conversation

@axelray-dev

Copy link
Copy Markdown
Contributor

What's broken

Instantiating a component with a bare Annotated[Iterable, HAYSTACK_VARIADIC_ANNOTATION] annotation (no type argument) crashes with IndexError: tuple index out of range in InputSocket.__post_init__. The crash happens at component instantiation time, bypassing static type checking. For example:

def run(self, inputs: Annotated[Iterable, HAYSTACK_VARIADIC_ANNOTATION]):

raises IndexError inside get_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, raises ComponentError with 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_error which creates a component with a bare Annotated[Iterable, HAYSTACK_VARIADIC_ANNOTATION] input and asserts that ComponentError is 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.

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
@vercel

vercel Bot commented Jun 3, 2026

Copy link
Copy Markdown

@axelray-dev is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@axelray-dev axelray-dev marked this pull request as ready for review June 3, 2026 01:59
@axelray-dev axelray-dev requested a review from a team as a code owner June 3, 2026 01:59
@axelray-dev axelray-dev requested review from sjrl and removed request for a team June 3, 2026 01:59
Comment thread haystack/core/component/types.py Outdated
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Jun 18, 2026
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/core/component
  types.py
Project Total  

This report was generated by python-coverage-comment-action

Move the local import of ComponentError inside InputSocket.__post_init__
to the top-level imports, consistent with the rest of the codebase.
@axelray-dev

Copy link
Copy Markdown
Contributor Author

Moved the import to module scope, thanks.

@sjrl sjrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sjrl sjrl merged commit 6674b9b into deepset-ai:main Jun 18, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: InputSocket.__post_init__ crashes with IndexError on unsubscripted Variadic type

2 participants