Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdk] TypeError with list input/output when list type is included #11536

Open
strangiato opened this issue Jan 18, 2025 · 2 comments
Open

[sdk] TypeError with list input/output when list type is included #11536

strangiato opened this issue Jan 18, 2025 · 2 comments
Assignees

Comments

@strangiato
Copy link

When attempting to use a list for an input/output of a component, if you specify the data type expected within the list such as list[str] or list[int], it returns the following error:

TypeError: Artifacts must have both a schema_title and a schema_version, separated by `@`. Got: list[int]

Where if you provide the an untyped list it works without issue.

Environment

  • KFP version:
    2.11
  • KFP SDK version:
    2.11
  • All dependencies version:

Steps to reproduce

Example code:

from kfp import compiler, dsl

@dsl.component()
def list_input_component(num_list: list[int]):
    print(num_list)

@dsl.component()
def list_output_component(num1:int, num2:int) -> list[int]:
    return [num1, num2]

@dsl.pipeline
def my_pipeline(x: int, y: int):
    list_task = list_input_component(num_list=[x,y])
    list_task2 = list_output_component(num1=x, num2=x)

if __name__ == "__main__":
    compiler.Compiler().compile(my_pipeline, package_path="my_pipeline.yaml"))

Expected result

Providing the type hinting as list[int] or whatever other datatype you expect is more pythonic as you generally want to avoid untyped lists. I would expect this to work instead of being required to provide a bare, untyped list

By replacing any instances of list[int] with list in the examples above, the pipeline is able to successfully compile.

Materials and Reference

https://www.kubeflow.org/docs/components/pipelines/user-guides/data-handling/parameters/

Full stack trace:

Traceback (most recent call last):
  File "/Users/my_user/code/kfp-component-test/pipelines/test-pipeline.py", line 5, in <module>
    @dsl.component()
     ^^^^^^^^^^^^^^^
  File "/Users/my_user/code/kfp-component-test/.venv/lib/python3.11/site-packages/kfp/dsl/component_decorator.py", line 126, in component
    return component_factory.create_component_from_func(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/my_user/code/kfp-component-test/.venv/lib/python3.11/site-packages/kfp/dsl/component_factory.py", line 589, in create_component_from_func
    component_spec = extract_component_interface(func)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/my_user/code/kfp-component-test/.venv/lib/python3.11/site-packages/kfp/dsl/component_factory.py", line 451, in extract_component_interface
    name_to_input_spec, name_to_output_spec = get_name_to_specs(
                                              ^^^^^^^^^^^^^^^^^^
  File "/Users/my_user/code/kfp-component-test/.venv/lib/python3.11/site-packages/kfp/dsl/component_factory.py", line 302, in get_name_to_specs
    name, list(name_to_input_specs))] = make_input_spec(
                                        ^^^^^^^^^^^^^^^^
  File "/Users/my_user/code/kfp-component-test/.venv/lib/python3.11/site-packages/kfp/dsl/component_factory.py", line 406, in make_input_spec
    return structures.InputSpec(
           ^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 8, in __init__
  File "/Users/my_user/code/kfp-component-test/.venv/lib/python3.11/site-packages/kfp/dsl/structures.py", line 57, in __post_init__
    self._validate_type()
  File "/Users/my_user/code/kfp-component-test/.venv/lib/python3.11/site-packages/kfp/dsl/structures.py", line 131, in _validate_type
    type_utils.validate_bundled_artifact_type(self.type)
  File "/Users/my_user/code/kfp-component-test/.venv/lib/python3.11/site-packages/kfp/dsl/types/type_utils.py", line 544, in validate_bundled_artifact_type
    raise TypeError(
TypeError: Artifacts must have both a schema_title and a schema_version, separated by `@`. Got: list[int]

Impacted by this bug? Give it a 👍.

strangiato added a commit to redhat-composer-ai/data-ingestion that referenced this issue Jan 18, 2025
@mahdikhashan
Copy link

I would like to work on this issue.

/assign

@mahdikhashan

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants