fix(iterator): raise TypeTransformerFailedError with a message to prevent IndexError in callers#3437
Open
devteamaegis wants to merge 1 commit into
Open
Conversation
…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.
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
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.