2020from openeo .rest ._datacube import (
2121 THIS ,
2222 UDF ,
23- _ensure_save_result ,
2423 _ProcessGraphAbstraction ,
2524 build_child_callback ,
2625)
@@ -194,7 +193,6 @@ def run_udf(
194193
195194 @openeo_process
196195 def save_result (self , format : Union [str , None ] = "GeoJSON" , options : dict = None ) -> SaveResult :
197- # TODO #401: guard against duplicate save_result nodes?
198196 pg = self ._build_pgnode (
199197 process_id = "save_result" ,
200198 arguments = {
@@ -206,6 +204,17 @@ def save_result(self, format: Union[str, None] = "GeoJSON", options: dict = None
206204 )
207205 return SaveResult (pg , connection = self ._connection )
208206
207+ def _auto_save_result (
208+ self ,
209+ format : Optional [str ] = None ,
210+ outputfile : Optional [Union [str , pathlib .Path ]] = None ,
211+ options : Optional [dict ] = None ,
212+ ) -> SaveResult :
213+ return self .save_result (
214+ format = format or (guess_format (outputfile ) if outputfile else None ) or self ._DEFAULT_VECTOR_FORMAT ,
215+ options = options ,
216+ )
217+
209218 def execute (self , * , validate : Optional [bool ] = None ) -> dict :
210219 """Executes the process graph."""
211220 return self ._connection .execute (self .flat_graph (), validate = validate )
@@ -230,7 +239,7 @@ def download(
230239 :param options: (optional) additional output format options.
231240 :param validate: Optional toggle to enable/prevent validation of the process graphs before execution
232241 (overruling the connection's ``auto_validate`` setting).
233- :param auto_add_save_result: Automatically add a ``save_result`` node to the process graph if there is none yet .
242+ :param auto_add_save_result: Automatically add a ``save_result`` node to the process graph.
234243
235244 .. versionchanged:: 0.21.0
236245 When not specified explicitly, output format is guessed from output file extension.
@@ -240,14 +249,7 @@ def download(
240249 """
241250 # TODO #278 centralize download/create_job/execute_job logic in DataCube, VectorCube, MlModel, ...
242251 if auto_add_save_result :
243- res = _ensure_save_result (
244- cube = self ,
245- format = format ,
246- options = options ,
247- weak_format = guess_format (outputfile ) if outputfile else None ,
248- default_format = self ._DEFAULT_VECTOR_FORMAT ,
249- method = "VectorCube.download()" ,
250- )
252+ res = self ._auto_save_result (format = format , outputfile = outputfile , options = options )
251253 else :
252254 res = self
253255 return self ._connection .download (res .flat_graph (), outputfile = outputfile , validate = validate )
@@ -287,7 +289,7 @@ def execute_batch(
287289 :param format_options: (optional) additional output format options
288290 :param validate: Optional toggle to enable/prevent validation of the process graphs before execution
289291 (overruling the connection's ``auto_validate`` setting).
290- :param auto_add_save_result: Automatically add a ``save_result`` node to the process graph if there is none yet .
292+ :param auto_add_save_result: Automatically add a ``save_result`` node to the process graph.
291293 :param show_error_logs: whether to automatically print error logs when the batch job failed.
292294 :param log_level: Optional minimum severity level for log entries that the back-end should keep track of.
293295 One of "error" (highest severity), "warning", "info", and "debug" (lowest severity).
@@ -310,14 +312,7 @@ def execute_batch(
310312 Added argument ``log_level``.
311313 """
312314 if auto_add_save_result :
313- res = _ensure_save_result (
314- cube = self ,
315- format = out_format ,
316- options = format_options ,
317- weak_format = guess_format (outputfile ) if outputfile else None ,
318- default_format = self ._DEFAULT_VECTOR_FORMAT ,
319- method = "VectorCube.execute_batch()" ,
320- )
315+ res = self ._auto_save_result (format = out_format , outputfile = outputfile , options = format_options )
321316 create_kwargs = {}
322317 else :
323318 res = self
@@ -373,7 +368,7 @@ def create_job(
373368 :param format_options: String Parameters for the job result format
374369 :param validate: Optional toggle to enable/prevent validation of the process graphs before execution
375370 (overruling the connection's ``auto_validate`` setting).
376- :param auto_add_save_result: Automatically add a ``save_result`` node to the process graph if there is none yet .
371+ :param auto_add_save_result: Automatically add a ``save_result`` node to the process graph.
377372 :param log_level: Optional minimum severity level for log entries that the back-end should keep track of.
378373 One of "error" (highest severity), "warning", "info", and "debug" (lowest severity).
379374
@@ -387,17 +382,12 @@ def create_job(
387382 """
388383 # TODO: avoid using all kwargs as format_options
389384 # TODO #278 centralize download/create_job/execute_job logic in DataCube, VectorCube, MlModel, ...
390- cube = self
391385 if auto_add_save_result :
392- cube = _ensure_save_result (
393- cube = cube ,
394- format = out_format ,
395- options = format_options or None ,
396- default_format = self ._DEFAULT_VECTOR_FORMAT ,
397- method = "VectorCube.create_job()" ,
398- )
386+ res = self ._auto_save_result (format = out_format , options = format_options or None )
387+ else :
388+ res = self
399389 return self ._connection .create_job (
400- process_graph = cube .flat_graph (),
390+ process_graph = res .flat_graph (),
401391 title = title ,
402392 description = description ,
403393 plan = plan ,
0 commit comments