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

Reset _has_been_called to False ahead of pipeline.connect #385

Merged
merged 4 commits into from
Feb 2, 2022
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
12 changes: 10 additions & 2 deletions src/zenml/pipelines/base_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,14 @@ def steps(self, steps: Dict[str, BaseStep]) -> NoReturn:
"""
raise PipelineInterfaceError("Cannot set steps manually!")

# TODO [ENG-376]: Enable specifying runtime configuration options either using
# **kwargs here or by passing a `RuntimeConfiguration` object or a
def _reset_step_flags(self) -> None:
"""Reset the _has_been_called flag at the beginning of a pipeline run,
to make sure a pipeline instance can be called more than once."""
for step in self.steps.values():
step._has_been_called = False

# TODO [ENG-376]: Enable specifying runtime configuration options either
# using **kwargs here or by passing a `RuntimeConfiguration` object or a
# path to a config file.
def run(
self,
Expand Down Expand Up @@ -287,6 +293,8 @@ def run(
},
)

self._reset_step_flags()

return stack.deploy_pipeline(
self, runtime_configuration=runtime_configuration
)
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/pipelines/test_base_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,16 @@ def test_setting_pipeline_parameter_name_when_initializing_pipeline(
assert step_instance.pipeline_parameter_name is None
one_step_pipeline(step_instance)
assert step_instance.pipeline_parameter_name == "step_"


def test_calling_a_pipeline_twice_raises_no_exception(
one_step_pipeline, empty_step
):
"""Tests that calling one pipeline instance twice does not raise
any exception."""

pipeline_instance = one_step_pipeline(empty_step())

with does_not_raise():
pipeline_instance.run()
pipeline_instance.run()