Skip to content

Commit 4f24107

Browse files
committed
Issue #742 fix legacy save_result/export_workspace usage pattern
1 parent 0548b13 commit 4f24107

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Fixed
1717

18+
- Fix legacy usage pattern to append `export_workspace` to `save_result` with generic `process()` helper method ([#742](https://github.com/Open-EO/openeo-python-client/issues/742))
19+
1820

1921
## [0.39.0] - 2025-02-25
2022

openeo/rest/stac_resource.py

+18
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ class StacResource(_ProcessGraphAbstraction):
3636
def __init__(self, graph: PGNode, connection: Optional[Connection] = None):
3737
super().__init__(pgnode=graph, connection=connection)
3838

39+
def process(
40+
self,
41+
process_id: str,
42+
arguments: Optional[dict] = None,
43+
namespace: Optional[str] = None,
44+
**kwargs,
45+
) -> StacResource:
46+
"""
47+
Generic helper to create a new StacResource by applying a process.
48+
49+
:param process_id: process id of the process.
50+
:param arguments: argument dictionary for the process.
51+
:param namespace: optional: process namespace
52+
"""
53+
pg = self._build_pgnode(process_id=process_id, arguments=arguments, namespace=namespace, **kwargs)
54+
# TODO: warn that actual return type can not or is not properly detected
55+
return StacResource(graph=pg, connection=self._connection)
56+
3957
@openeo_process
4058
def export_workspace(self, workspace: str, merge: Union[str, None] = None) -> StacResource:
4159
"""

tests/rest/test_result.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from openeo.rest.datacube import THIS
2+
from openeo.rest.result import SaveResult
3+
4+
5+
def test_legacy_save_result_export_workspace(dummy_backend):
6+
"""https://github.com/Open-EO/openeo-python-client/issues/742"""
7+
8+
s2 = dummy_backend.connection.load_collection("S2")
9+
saved = s2.save_result(format="GTiff")
10+
result = saved.process("export_workspace", arguments={"data": THIS, "workspace": "foobar"})
11+
result.download()
12+
assert dummy_backend.get_pg() == {
13+
"loadcollection1": {
14+
"process_id": "load_collection",
15+
"arguments": {"id": "S2", "spatial_extent": None, "temporal_extent": None},
16+
},
17+
"saveresult1": {
18+
"process_id": "save_result",
19+
"arguments": {"data": {"from_node": "loadcollection1"}, "format": "GTiff", "options": {}},
20+
},
21+
"exportworkspace1": {
22+
"process_id": "export_workspace",
23+
"arguments": {"data": {"from_node": "saveresult1"}, "workspace": "foobar"},
24+
"result": True,
25+
},
26+
}

0 commit comments

Comments
 (0)