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

Improve error message when trying to unpack a step artifact #2674

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/zenml/steps/entrypoint_function_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Callable,
Dict,
NamedTuple,
NoReturn,
Optional,
Sequence,
Type,
Expand Down Expand Up @@ -103,6 +104,20 @@ def __init__(
self.annotation = annotation
self.pipeline = pipeline

def __iter__(self) -> NoReturn:
"""Raise a custom error if someone is trying to iterate this object.

Raises:
StepInterfaceError: If trying to iterate this object.
"""
raise StepInterfaceError(
"Unable to unpack step artifact. This error is probably because "
"you're trying to unpack the return value of your step but the "
"step only returns a single artifact. For more information on how "
"to add type annotations to your step to indicate multiple "
"artifacts visit https://docs.zenml.io/user-guide/advanced-guide/pipelining-features/managing-steps#type-annotations."
)


def validate_reserved_arguments(
signature: inspect.Signature, reserved_arguments: Sequence[str]
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/steps/test_base_step_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,20 @@ def test_pipeline():

with does_not_raise():
test_pipeline()


@step
def step_with_single_output() -> int:
return 1


def test_unpacking_step_artifact_raises_custom_exception():
"""Tests that unpacking an artifact returned by a step inside a pipeline
raises a custom exception with explanation on how to solve the issue."""

@pipeline
def test_pipeline():
a, b = step_with_single_output()

with pytest.raises(StepInterfaceError):
test_pipeline()
Loading