Skip to content

Commit

Permalink
Issue #404 Pass validate parameter through in datacube
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanKJSchreurs committed Oct 3, 2023
1 parent 4de7d52 commit 876a7c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions openeo/rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ def download(
graph: Union[dict, FlatGraphableMixin, str, Path],
outputfile: Union[Path, str, None] = None,
timeout: Optional[int] = None,
validate: bool = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
) -> Union[None, bytes]:
"""
Downloads the result of a process graph synchronously,
Expand Down Expand Up @@ -1541,7 +1541,7 @@ def execute(
self,
process_graph: Union[dict, str, Path],
timeout: Optional[int] = None,
validate: bool = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
):
"""
Execute a process graph synchronously and return the result (assumed to be JSON).
Expand Down Expand Up @@ -1570,7 +1570,7 @@ def create_job(
plan: Optional[str] = None,
budget: Optional[float] = None,
additional: Optional[dict] = None,
validate: bool = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
validate: Optional[bool] = VALIDATE_PROCESS_GRAPH_BY_DEFAULT,
) -> BatchJob:
"""
Create a new job from given process graph on the back-end.
Expand Down
18 changes: 12 additions & 6 deletions openeo/rest/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@

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 @@ -1945,6 +1949,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,
) -> Union[None, bytes]:
"""
Execute synchronously and download the raster data cube, e.g. as GeoTIFF.
Expand All @@ -1961,7 +1966,7 @@ def download(
# TODO #401/#449 don't guess/override format if there is already a save_result with format?
format = guess_format(outputfile)
cube = self._ensure_save_result(format=format, options=options)
return self._connection.download(cube.flat_graph(), outputfile)
return self._connection.download(cube.flat_graph(), outputfile, validate=validate)

def validate(self) -> List[dict]:
"""
Expand Down Expand Up @@ -2062,6 +2067,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,
# TODO: avoid `format_options` as keyword arguments
**format_options,
) -> BatchJob:
Expand All @@ -2081,9 +2087,7 @@ def execute_batch(
# TODO #401/#449 don't guess/override format if there is already a save_result with format?
out_format = guess_format(outputfile)

job = self.create_job(
out_format=out_format, job_options=job_options, **format_options
)
job = self.create_job(out_format=out_format, job_options=job_options, validate=validate, **format_options)
return job.run_synchronous(
outputfile=outputfile,
print=print, max_poll_interval=max_poll_interval, connection_retry_interval=connection_retry_interval
Expand All @@ -2098,6 +2102,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,
# TODO: avoid `format_options` as keyword arguments
**format_options,
) -> BatchJob:
Expand Down Expand Up @@ -2127,6 +2132,7 @@ def create_job(
description=description,
plan=plan,
budget=budget,
validate=validate,
additional=job_options,
)

Expand Down Expand Up @@ -2162,9 +2168,9 @@ def save_user_defined_process(
returns=returns, categories=categories, examples=examples, links=links,
)

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

@staticmethod
@deprecated(reason="Use :py:func:`openeo.udf.run_code.execute_local_udf` instead", version="0.7.0")
Expand Down

0 comments on commit 876a7c2

Please sign in to comment.