Skip to content

Commit 3d62acc

Browse files
committed
EP-4012: add support for process graph validation
1 parent 03308a9 commit 3d62acc

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Add proper support for child callbacks in `fit_curve` and `predict_curve` ([#229](https://github.com/Open-EO/openeo-python-client/issues/229))
1818
- `ProcessBuilder`: Add support for `array_element(data, n)` through `data[n]` syntax ([#228](https://github.com/Open-EO/openeo-python-client/issues/228))
1919
- `ProcessBuilder`: Add support for `eq` and `neq` through `==` and `!=` operators (EP-4011)
20+
- Add `DataCube.validate()` for process graph validation (EP-4012 related)
2021

2122

2223
### Changed

openeo/rest/connection.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,15 @@ def user_defined_process(self, user_defined_process_id: str) -> RESTUserDefinedP
753753
"""
754754
return RESTUserDefinedProcess(user_defined_process_id=user_defined_process_id, connection=self)
755755

756-
def validate_processgraph(self, process_graph):
757-
# Endpoint: POST /validate
758-
raise NotImplementedError()
756+
def validate_process_graph(self, process_graph: dict) -> List[dict]:
757+
"""
758+
Validate a process graph without executing it.
759+
760+
:param process_graph: (flat) dict representing process graph
761+
:return: list of errors (dictionaries with "code" and "message" fields)
762+
"""
763+
request = {"process_graph": process_graph}
764+
return self.post(path="/validation", json=request, expected_status=200).json()["errors"]
759765

760766
@property
761767
def _api_version(self) -> ComparableVersion:

openeo/rest/datacube.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,14 @@ def download(self, outputfile: Union[str, pathlib.Path, None] = None, format: st
14831483
cube = self.save_result(format=format, options=options)
14841484
return self._connection.download(cube.flat_graph(), outputfile)
14851485

1486+
def validate(self) -> List[dict]:
1487+
"""
1488+
Validate a process graph without executing it.
1489+
1490+
:return: list of errors (dictionaries with "code" and "message" fields)
1491+
"""
1492+
return self._connection.validate_process_graph(self.flat_graph())
1493+
14861494
def tiled_viewing_service(self, type: str, **kwargs) -> Service:
14871495
return self._connection.create_service(self.flat_graph(), type=type, **kwargs)
14881496

tests/rest/datacube/test_datacube100.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,3 +1271,22 @@ def model(x, parameters):
12711271
},
12721272
}
12731273
assert res.graph == expected
1274+
1275+
1276+
def test_validation(con100, requests_mock):
1277+
def validation(request, context):
1278+
assert request.json() == {"process_graph": {
1279+
'loadcollection1': {
1280+
'process_id': 'load_collection',
1281+
'arguments': {'id': 'S2', 'spatial_extent': None, 'temporal_extent': None},
1282+
'result': True,
1283+
}
1284+
}}
1285+
return {"errors": [{"code": "Invalid", "message": "Invalid process graph"}]}
1286+
1287+
m = requests_mock.post(API_URL + "/validation", json=validation)
1288+
1289+
cube = con100.load_collection("S2")
1290+
errors = cube.validate()
1291+
assert errors == [{"code": "Invalid", "message": "Invalid process graph"}]
1292+
assert m.call_count == 1

0 commit comments

Comments
 (0)