Skip to content

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

@pimdh

Description

@pimdh

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?

  • Yes

Have you read the Code of Conduct?

  • Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinguntriagedThis issues has not yet been looked at by the Maintainers

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions