fix(io_models): guard against IndexError for bare iterator return annotations#5626
Open
devteamaegis wants to merge 1 commit into
Open
fix(io_models): guard against IndexError for bare iterator return annotations#5626devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
…otations get_args() returns an empty tuple for unparameterized generics like t.Iterator, so indexing [0] unconditionally raised IndexError. Fall back to t.Any when no type argument is present. Fixes bentoml#5625
frostming
approved these changes
Jun 2, 2026
18deb82 to
808d8d2
Compare
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
IODescriptor.from_output()raisesIndexError: tuple index out of rangewhenever a service method is annotated with an unparameterized iterator type (t.Iterator,t.Generator,t.AsyncIterator,t.AsyncGenerator, or theircollections.abcequivalents). Service startup crashes before any request is served.Why it happens
is_iterator_type()correctly returnsTruefor bare generics, butget_args()returns an empty tuple()for types with no type parameters. Line 435 unconditionally indexes position 0 without a bounds check. The surroundingtry/exceptonly catchesValueErrorandTypeError, so theIndexErrorescapes.Fix
Added a one-line guard:
args = get_args(return_annotation); return_annotation = args[0] if args else t.Any. When no type argument is present the descriptor defaults tot.Any, which is the same behaviour used when the return annotation is absent entirely.Test
Added
tests/unit/_bentoml_sdk/test_io_models.py::test_from_output_bare_iterator_does_not_raisewhich callsIODescriptor.from_output()with a-> t.Iteratorannotated function and asserts it returns without raising.Fixes #5625