Skip to content

Commit

Permalink
Workaround in-place modification of process graphs in _evaluate_proce…
Browse files Browse the repository at this point in the history
…ss_graph_process

in-place modification might break re-JSON-encoding

related to Open-EO/openeo-geopyspark-driver#567
  • Loading branch information
soxofaan committed Nov 9, 2023
1 parent 3c08540 commit bf93bff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# pylint: disable=unused-argument

import calendar
import copy
import datetime
import logging
import math
Expand Down Expand Up @@ -347,6 +348,8 @@ def evaluate(
) -> Union[DriverDataCube, Any]:
"""
Converts the json representation of a (part of a) process graph into the corresponding Python data cube.
Warning: this function could manipulate the given process graph dict in-place (see `convert_node`).
"""

if "version" not in env:
Expand Down Expand Up @@ -379,6 +382,11 @@ def evaluate(


def convert_node(processGraph: Union[dict, list], env: EvalEnv = None):
"""
Warning: this function could manipulate the given process graph dict in-place,
e.g. by adding a "result_cache" key (see lower).
"""
if isinstance(processGraph, dict):
if 'process_id' in processGraph:
process_id = processGraph['process_id']
Expand All @@ -396,6 +404,8 @@ def convert_node(processGraph: Union[dict, list], env: EvalEnv = None):
if isinstance(comparison,bool) and comparison:
_log.info(f"Reusing an already evaluated subgraph for process {process_id}")
return cached
# TODO: this manipulates the process graph, while we often assume it's immutable.
# Adding complex data structures could also interfere with attempts to (re)encode the process graph as JSON again.
processGraph["result_cache"] = process_result
return process_result
elif 'node' in processGraph:
Expand Down Expand Up @@ -1735,6 +1745,9 @@ def _evaluate_process_graph_process(
else:
raise ProcessParameterRequiredException(process=process_id, parameter=name)
env = env.push_parameters(args)

# Make a deep copy of the process graph (as the `evaluate` pipeline might modify it)
process_graph = copy.deepcopy(process_graph)
return evaluate(process_graph, env=env, do_dry_run=False)


Expand Down
2 changes: 1 addition & 1 deletion openeo_driver/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.76.0a1"
__version__ = "0.76.1a1"

0 comments on commit bf93bff

Please sign in to comment.