From 405be57a5d8ace04da3eeb10c825805f5c95d277 Mon Sep 17 00:00:00 2001 From: Johan Schreurs Date: Wed, 4 Oct 2023 11:01:46 +0200 Subject: [PATCH] Issue #404 Remove toggle VALIDATE_PROCESS_GRAPH_BY_DEFAULT Now execute / download request will always validate process graph unless user asks to skip validation. --- openeo/rest/connection.py | 11 +++-------- openeo/rest/datacube.py | 12 ++++-------- openeo/rest/vectorcube.py | 13 ++++--------- tests/rest/test_connection.py | 1 - 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/openeo/rest/connection.py b/openeo/rest/connection.py index d9e0e7566..f9569ad4f 100644 --- a/openeo/rest/connection.py +++ b/openeo/rest/connection.py @@ -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""" @@ -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, @@ -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). @@ -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. diff --git a/openeo/rest/datacube.py b/openeo/rest/datacube.py index 9190fd83c..5231e523c 100644 --- a/openeo/rest/datacube.py +++ b/openeo/rest/datacube.py @@ -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] @@ -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. @@ -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: @@ -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: @@ -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) diff --git a/openeo/rest/vectorcube.py b/openeo/rest/vectorcube.py index b31225217..8d2271c72 100644 --- a/openeo/rest/vectorcube.py +++ b/openeo/rest/vectorcube.py @@ -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': @@ -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) @@ -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. @@ -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: @@ -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: """ diff --git a/tests/rest/test_connection.py b/tests/rest/test_connection.py index 589518738..0f2f8c7ac 100644 --- a/tests/rest/test_connection.py +++ b/tests/rest/test_connection.py @@ -30,7 +30,6 @@ RestApiConnection, connect, paginate, - VALIDATE_PROCESS_GRAPH_BY_DEFAULT, ) from openeo.rest.vectorcube import VectorCube from openeo.util import ContextTimer