Skip to content

fix(iterator): raise TypeTransformerFailedError with a message to prevent IndexError in callers#3437

Open
devteamaegis wants to merge 1 commit into
flyteorg:masterfrom
devteamaegis:bugfix/iterator-indexerror-empty-args
Open

fix(iterator): raise TypeTransformerFailedError with a message to prevent IndexError in callers#3437
devteamaegis wants to merge 1 commit into
flyteorg:masterfrom
devteamaegis:bugfix/iterator-indexerror-empty-args

Conversation

@devteamaegis
Copy link
Copy Markdown

What's broken

When IteratorTransformer.to_python_value receives a non-collection literal (e.g. a scalar), it catches the AttributeError from lv.collection.literals and re-raises TypeTransformerFailedError() with no arguments (args = ()). Multiple callers in promise.py (lines 103, 1235, 1360), base_task.py (line 312), and base_connector.py (line 350) then do exc.args = (f"...{exc.args[0]}...",) to enrich the error message. Because exc.args is an empty tuple, accessing exc.args[0] raises IndexError: tuple index out of range, which swallows the original type conversion failure entirely.

Why it happens

TypeTransformerFailedError() was raised with no arguments, leaving args as an empty tuple, which callers throughout the codebase assume is non-empty.

Fix

Replace the bare except/re-raise with an explicit None-check on lv.collection and pass a descriptive message string to TypeTransformerFailedError, so exc.args[0] is always valid for callers to safely index.

Test

Added test_to_python_value_non_collection_raises_with_message in tests/flytekit/unit/types/iterator/test_iterator.py that passes a scalar literal to to_python_value and asserts the raised TypeTransformerFailedError has a non-empty args tuple.

…vent IndexError in callers

IteratorTransformer.to_python_value previously raised TypeTransformerFailedError()
with no arguments. Callers in promise.py, base_task.py, and base_connector.py all
access exc.args[0] to enrich the error message; with an empty args tuple this caused
an IndexError that swallowed the original type conversion failure entirely.

Replace the bare except/re-raise with an explicit None-check on lv.collection and
raise TypeTransformerFailedError with a descriptive message, ensuring exc.args[0]
is always valid.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant