RNHTTR commented on code in PR #72275:
URL: https://github.com/apache/airflow/pull/72275#discussion_r3916296819


##########
providers/google/src/airflow/providers/google/cloud/transfers/gcs_to_gcs.py:
##########
@@ -607,8 +609,15 @@ def _copy_single_object(self, hook, source_object, 
destination_object) -> str |
             **rewrite_kwargs,
         )
 
-        if self.move_object:
-            hook.delete(self.source_bucket, source_object)
+        try:
+            if self.move_object:
+                hook.delete(self.source_bucket, source_object)
+
+        # Handle case where the file has already been deleted and a NotFound 
exception is raised
+        except NotFound:
+            self.log.warning(
+                "Object %s/%s already deleted (404 on move); continuing", 
self.source_bucket, source_object

Review Comment:
   ```suggestion
                   "Object %s does not exist in the source bucket %s", 
self.source_object, source_bucket
   ```



##########
providers/google/tests/unit/google/cloud/transfers/test_gcs_to_gcs.py:
##########
@@ -547,6 +548,39 @@ def 
test_executes_with_multiple_items_in_source_objects(self, mock_hook):
             any_order=True,
         )
 
+    @mock.patch("airflow.providers.google.cloud.transfers.gcs_to_gcs.GCSHook")
+    def test_executes_with_source_objects_not_found(self, mock_hook, caplog):
+        """Handle a file NotFound exception when attempting to delete source 
object."""
+        operator = GCSToGCSOperator(
+            task_id=TASK_ID,
+            source_bucket=TEST_BUCKET,
+            source_objects=SOURCE_OBJECTS_SINGLE_FILE,
+            move_object=True,
+        )
+
+        mock_hook.return_value.delete.side_effect = NotFound("Object not 
found")
+
+        operator.execute(None)
+
+        expected_object = SOURCE_OBJECTS_SINGLE_FILE[0]
+        expected_message = f"Object {TEST_BUCKET}/{expected_object} already 
deleted (404 on move); continuing"

Review Comment:
   ```suggestion
           expected_message = f"Object {expected_object} does not exist in the 
source bucket {TEST_BUCKET}"
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to