flyte icon indicating copy to clipboard operation
flyte copied to clipboard

[BUG] [flytekit] Incorrect error message when converting types (referring to wrong argument)

Open pimdh opened this issue 3 months ago • 1 comments

Flyte & Flytekit version

Flytekit 1.16.3 (also seems present on master)

Describe the bug

When there's an error in type conversion, the error message always refer the last argument, even if that's not where the error is. This is caused by a bug in the following code: https://github.com/flyteorg/flytekit/blob/9effe915c0dfdd1b9870ce0539ed0aec3ccda80c/flytekit/core/type_engine.py#L1579 The variable k in this code will always refer to the final arg, even if that's not where the error occurred.

To reproduce, run

from flytekit import task, workflow
from flytekit.types.directory import FlyteDirectory


@task
def process_directory(input_dir: FlyteDirectory, description: str) -> str:
    """Process a directory with a description."""
    return f"Processing directory: {input_dir.path} with description: {description}"


@workflow
def main_workflow(input_dir: FlyteDirectory, description: str) -> str:
    """Main workflow that calls the task."""
    return process_directory(input_dir=input_dir, description=description)


if __name__ == "__main__":
    # Incorrectly passing empty string as first argument (should be FlyteDirectory)
    result = main_workflow(input_dir=FlyteDirectory(""), description="Sample processing job")
    print(result)

which will give the unhelpful errormessage:

TypeTransformerFailedError: Error encountered while converting inputs of 'example_flyte_task.process_directory':
  Error converting input 'description' at position 1:
Literal value: Flyte Serialized object (Literal):
  scalar:
    primitive:
      string_value: Sample processing job
Expected Python type: <class 'str'>
Exception: USER:AssertionError: error=Expected a directory, but the given uri '' is not a directory.

Expected behavior

I'd expect an error message like the following (achieved by removing the 2nd arg):

TypeTransformerFailedError: Error encountered while converting inputs of 'example_flyte_task.process_directory':
  Error converting input 'input_dir' at position 0:
Literal value: Flyte Serialized object (Literal):
  scalar:
    blob:
      metadata:
        type:
          dimensionality: 1
Expected Python type: <class 'flytekit.types.directory.types.FlyteDirectory'>
Exception: USER:AssertionError: error=Expected a directory, but the given uri '' is not a directory.

Additional context to reproduce

No response

Screenshots

No response

Are you sure this issue hasn't been raised already?

  • [x] Yes

Have you read the Code of Conduct?

  • [x] Yes

pimdh avatar Sep 22 '25 17:09 pimdh

It could be possible that Flytekit's error reporting for type conversion issues always references the last argument, even if the error is in a different input. This seems to be due to a bug in the error handling logic, as described in your linked code and demonstrated by your example. The error message incorrectly points to the 'description' argument, even though the actual problem is with 'input_dir'—this is not the expected behavior.

Though I'm not entirely certain, it might be that this specific bug is not explicitly documented in the available data sources, but related issues with error messages and type conversion have been discussed, such as improving error messages for type mismatches and clarifying which input caused the error. Would you like more detail on how Flytekit's type conversion and error reporting work, or on possible workarounds until this is fixed?

Sources:


This is an AI-generated response and your feedback is appreciated! Please leave a 👍 if this is helpful and 👎 if it is not.

Mention @runllm to ask follow-up questions. See runllm.com for more!

runllm[bot] avatar Sep 22 '25 17:09 runllm[bot]