You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Programmer-RD-AI (via GitHub)" <gi...@apache.org> on 2025/09/30 16:11:00 UTC

Re: [PR] Fix: Make SFTPOperator delete idempotent (return a warning instead of a error when file is already absent) [airflow]

Programmer-RD-AI commented on code in PR #56217:
URL: https://github.com/apache/airflow/pull/56217#discussion_r2392148123


##########
providers/sftp/src/airflow/providers/sftp/operators/sftp.py:
##########
@@ -206,10 +206,18 @@ def execute(self, context: Any) -> str | list[str] | None:
                 for _remote_filepath in remote_filepath_array:
                     file_msg = f"{_remote_filepath}"
                     self.log.info("Starting to delete %s", file_msg)
-                    if self.sftp_hook.isdir(_remote_filepath):
-                        self.sftp_hook.delete_directory(_remote_filepath, include_files=True)
-                    else:
-                        self.sftp_hook.delete_file(_remote_filepath)
+                    try:
+                        if self.sftp_hook.isdir(_remote_filepath):
+                            self.sftp_hook.delete_directory(_remote_filepath, include_files=True)
+                        else:
+                            self.sftp_hook.delete_file(_remote_filepath)
+                    except OSError as e:
+                        if "no such file" in str(e).lower():

Review Comment:
   i think checking based on the text of the error is a bad idea here, isn't the OSError being raised enough to know that it was due to the file or directory not being found in the path? or if there is a specific error you can expect then that would work as well



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org