Skip to content

Commit

Permalink
Issue #404 Remove toggle VALIDATE_PROCESS_GRAPH_BY_DEFAULT
Browse files Browse the repository at this point in the history
Now execute / download request will always validate process graph unless user asks to skip validation.
  • Loading branch information
JohanKJSchreurs committed Oct 4, 2023
1 parent ec31b84 commit 405be57
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
11 changes: 3 additions & 8 deletions openeo/rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@
DEFAULT_TIMEOUT_SYNCHRONOUS_EXECUTE = 30 * 60


# TODO: remove temporary constant that is intended for refactoring
# constant for refactoring to switch default validation of process graph on or off.
VALIDATE_PROCESS_GRAPH_BY_DEFAULT = True


class RestApiConnection:
"""Base connection class implementing generic REST API request functionality"""

Expand Down Expand Up @@ -1506,7 +1501,7 @@ def download(
graph: Union[dict, FlatGraphableMixin, str, Path],
outputfile: Union[Path, str, None] = None,
timeout: Optional[int] = None,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = True,
) -> Union[None, bytes]:
"""
Downloads the result of a process graph synchronously,
Expand Down Expand Up @@ -1541,7 +1536,7 @@ def execute(
self,
process_graph: Union[dict, str, Path],
timeout: Optional[int] = None,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = True,
):
"""
Execute a process graph synchronously and return the result (assumed to be JSON).
Expand Down Expand Up @@ -1570,7 +1565,7 @@ def create_job(
plan: Optional[str] = None,
budget: Optional[float] = None,
additional: Optional[dict] = None,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = True,
) -> BatchJob:
"""
Create a new job from given process graph on the back-end.
Expand Down
12 changes: 4 additions & 8 deletions openeo/rest/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@

log = logging.getLogger(__name__)

# TODO: remove temporary constant that is intended for refactoring
# constant for refactoring to switch default validation of process graph on or off.
VALIDATE_PROCESS_GRAPH_BY_DEFAULT = True


# Type annotation aliases
InputDate = Union[str, datetime.date, Parameter, PGNode, ProcessBuilderBase, None]
Expand Down Expand Up @@ -1949,7 +1945,7 @@ def download(
outputfile: Optional[Union[str, pathlib.Path]] = None,
format: Optional[str] = None,
options: Optional[dict] = None,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = True,
) -> Union[None, bytes]:
"""
Execute synchronously and download the raster data cube, e.g. as GeoTIFF.
Expand Down Expand Up @@ -2067,7 +2063,7 @@ def execute_batch(
max_poll_interval: float = 60,
connection_retry_interval: float = 30,
job_options: Optional[dict] = None,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = True,
# TODO: avoid `format_options` as keyword arguments
**format_options,
) -> BatchJob:
Expand Down Expand Up @@ -2102,7 +2098,7 @@ def create_job(
plan: Optional[str] = None,
budget: Optional[float] = None,
job_options: Optional[dict] = None,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = True,
# TODO: avoid `format_options` as keyword arguments
**format_options,
) -> BatchJob:
Expand Down Expand Up @@ -2168,7 +2164,7 @@ def save_user_defined_process(
returns=returns, categories=categories, examples=examples, links=links,
)

def execute(self, validate: bool = VALIDATE_PROCESS_GRAPH_BY_DEFAULT) -> dict:
def execute(self, validate: Optional[bool] = True) -> dict:
"""Executes the process graph of the imagery. """
return self._connection.execute(self.flat_graph(), validate=validate)

Expand Down
13 changes: 4 additions & 9 deletions openeo/rest/vectorcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
from openeo import Connection


# TODO: remove temporary constant that is intended for refactoring
# constant for refactoring to switch default validation of process graph on or off.
VALIDATE_PROCESS_GRAPH_BY_DEFAULT = False


class VectorCube(_ProcessGraphAbstraction):
"""
A Vector Cube, or 'Vector Collection' is a data structure containing 'Features':
Expand Down Expand Up @@ -231,7 +226,7 @@ def _ensure_save_result(
cube = self.save_result(format=format or "GeoJSON", options=options)
return cube

def execute(self, validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT) -> dict:
def execute(self, validate: Optional[bool] = True) -> dict:
"""Executes the process graph of the imagery."""
return self._connection.execute(self.flat_graph(), validate=validate)

Expand All @@ -240,7 +235,7 @@ def download(
outputfile: Optional[Union[str, pathlib.Path]] = None,
format: Optional[str] = None,
options: Optional[dict] = None,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = True,
) -> Union[None, bytes]:
"""
Execute synchronously and download the vector cube.
Expand Down Expand Up @@ -272,7 +267,7 @@ def execute_batch(
max_poll_interval: float = 60,
connection_retry_interval: float = 30,
job_options: Optional[dict] = None,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = True,
# TODO: avoid using kwargs as format options
**format_options,
) -> BatchJob:
Expand Down Expand Up @@ -310,7 +305,7 @@ def create_job(
plan: Optional[str] = None,
budget: Optional[float] = None,
job_options: Optional[dict] = None,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = True,
**format_options,
) -> BatchJob:
"""
Expand Down
1 change: 0 additions & 1 deletion tests/rest/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
RestApiConnection,
connect,
paginate,
VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
)
from openeo.rest.vectorcube import VectorCube
from openeo.util import ContextTimer
Expand Down

0 comments on commit 405be57

Please sign in to comment.