Skip to content

Commit

Permalink
Issue #604/#644 explicitly use default value from schema as fallback
Browse files Browse the repository at this point in the history
improves long term traceability and observability
  • Loading branch information
soxofaan committed Oct 11, 2024
1 parent 4e04351 commit 04bc791
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions openeo/extra/job_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ def create_job_db(path: Union[str, Path], df: pd.DataFrame, *, on_exists: str =
class UDPJobFactory:
"""
Batch job factory based on a parameterized process definition
(e.g a user-defined process (UDP) or a remote process definitions),
(e.g a user-defined process (UDP) or a remote process definition),
to be used together with :py:class:`MultiBackendJobManager`.
"""

Expand Down Expand Up @@ -946,9 +946,13 @@ def start_job(self, row: pd.Series, connection: Connection, **_) -> BatchJob:
elif name in self._parameter_defaults:
# Fallback on default values from constructor
value = self._parameter_defaults[name]
elif parameter.has_default():
# Explicitly use default value from parameter schema
value = parameter.default
elif parameter.optional:
# Skip optional parameters without any fallback default value
continue
else:
if parameter.optional:
continue
raise ValueError(f"Missing required parameter {name!r} for process {self._process_id!r}")

# TODO: validation or normalization based on schema?
Expand Down
4 changes: 2 additions & 2 deletions tests/extra/test_job_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ def test_basic(self, con120, dummy_backend):
"increment1": {
"process_id": "increment",
"namespace": "https://remote.test/increment.json",
"arguments": {"data": 123},
"arguments": {"data": 123, "increment": 1},
"result": True,
}
},
Expand All @@ -1052,7 +1052,7 @@ def test_basic(self, con120, dummy_backend):
@pytest.mark.parametrize(
["parameter_defaults", "row", "expected_arguments"],
[
(None, {"data": 123}, {"data": 123}),
(None, {"data": 123}, {"data": 123, "increment": 1}),
(None, {"data": 123, "increment": 5}, {"data": 123, "increment": 5}),
({"increment": 5}, {"data": 123}, {"data": 123, "increment": 5}),
({"increment": 5}, {"data": 123, "increment": 1000}, {"data": 123, "increment": 1000}),
Expand Down

0 comments on commit 04bc791

Please sign in to comment.