diff --git a/projects/vdk-core/src/vdk/internal/builtin_plugins/run/standalone_data_job.py b/projects/vdk-core/src/vdk/internal/builtin_plugins/run/standalone_data_job.py index fe0db6ebcc..0d9a12c960 100644 --- a/projects/vdk-core/src/vdk/internal/builtin_plugins/run/standalone_data_job.py +++ b/projects/vdk-core/src/vdk/internal/builtin_plugins/run/standalone_data_job.py @@ -20,9 +20,9 @@ from vdk.internal.builtin_plugins.run.data_job import JobArguments from vdk.internal.builtin_plugins.run.execution_state import ExecutionStateStoreKeys from vdk.internal.builtin_plugins.run.execution_tracking import ExecutionTrackingPlugin -from vdk.internal.builtin_plugins.run.file_based_step import TYPE_PYTHON from vdk.internal.builtin_plugins.run.job_context import JobContext from vdk.internal.builtin_plugins.run.step import Step +from vdk.internal.builtin_plugins.run.step import StepBuilder from vdk.internal.core.config import ConfigurationBuilder from vdk.internal.core.context import CoreContext from vdk.internal.core.statestore import StateStore @@ -122,6 +122,20 @@ def __init__( self._core_context = core_context self._job_context = None + def __override_with_noop_step(self): + noop_step = Step( + name="NoOpStep", + type="noop", + runner_func=lambda _step, _job_input: True, # Intentional noop + file_path=Path(__file__), + job_dir=self._job_context.job_directory, + ) + log.debug( + f"StandaloneDataJob will ignore following steps of the data job {self._job_context.step_builder}" + ) + self._job_context.step_builder = StepBuilder() + self._job_context.step_builder.add_step(noop_step) + def __enter__(self) -> IJobInput: try: self._core_context.plugin_registry.load_plugin_with_hooks_impl( @@ -148,6 +162,8 @@ def __enter__(self) -> IJobInput: cast(JobRunHookSpecs, self._plugin_registry.hook()).initialize_job( context=self._job_context ) + self.__override_with_noop_step() + cast(JobRunHookSpecs, self._plugin_registry.hook()).run_job( context=self._job_context ) diff --git a/projects/vdk-core/tests/functional/run/test_run_standalone_data_job.py b/projects/vdk-core/tests/functional/run/test_run_standalone_data_job.py index 70c9faf468..6db82ad389 100644 --- a/projects/vdk-core/tests/functional/run/test_run_standalone_data_job.py +++ b/projects/vdk-core/tests/functional/run/test_run_standalone_data_job.py @@ -8,16 +8,18 @@ from functional.run import util from vdk.api.plugin.hook_markers import hookimpl from vdk.internal.builtin_plugins.run.execution_state import ExecutionStateStoreKeys +from vdk.internal.builtin_plugins.run.job_context import JobContext from vdk.internal.builtin_plugins.run.standalone_data_job import ( StandaloneDataJobFactory, ) +from vdk.internal.builtin_plugins.run.step import Step ExecutedStandaloneDataJobDetails = collections.namedtuple( "ExecutedStandalongDataJob", "hook_tracker job_input_name" ) -@pytest.fixture(scope="module") +@pytest.fixture def executed_standalone_data_job(): hook_tracker = util.HookCallTracker() job_input_name = "unknown" @@ -124,3 +126,34 @@ def vdk_start( "--arguments", '{"a": "b"}', ] + + +def test_standalone_data_job_ignore_steps_added_by_other_plugins( + executed_standalone_data_job, +): + class AddNewStep: + def __init__(self): + self.step_executed = [] + + @hookimpl + def initialize_job(self, context: JobContext): + def func(_step, _job_input): + self.step_executed.append("") + return True + + step = Step( + name="NoOpStep", + type="noop", + runner_func=func, + file_path=Path(__file__), + job_dir=context.job_directory, + ) + context.step_builder.add_step(step) + + new_step_plugin = AddNewStep() + with StandaloneDataJobFactory.create( + data_job_directory=Path(__file__), extra_plugins=[new_step_plugin] + ) as job_input: + pass + + assert len(new_step_plugin.step_executed) == 0