Skip to content

BUG: IndexError in IODescriptor.from_output() with bare (unparameterized) iterator return annotations #5625

@devteamaegis

Description

@devteamaegis

What breaks

IODescriptor.from_output() crashes with an IndexError when a service method's return annotation is an unparameterized iterator type such as t.Iterator, t.Generator, t.AsyncIterator, or t.AsyncGenerator (and their collections.abc equivalents).

How to trigger

import typing as t
from _bentoml_sdk.io_models import IODescriptor

def my_stream_fn() -> t.Iterator:
    yield 1

IODescriptor.from_output(my_stream_fn)  # raises IndexError

Traceback

File "src/_bentoml_sdk/io_models.py", line 435, in from_output
    return_annotation = get_args(return_annotation)[0]
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: tuple index out of range

Root cause

is_iterator_type() correctly returns True for bare generics, but get_args() returns an empty tuple () for unparameterized types. Line 435 unconditionally indexes position 0 without checking the length first. The surrounding try/except on lines 447–450 only catches ValueError and TypeError, so the IndexError escapes and crashes service startup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions