Skip to content

Commit

Permalink
Fix the gcp_gcs_delete_objects on empty list (#32383)
Browse files Browse the repository at this point in the history
  • Loading branch information
yupbank committed Jul 6, 2023
1 parent becfb3c commit e7587b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/providers/google/cloud/operators/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def execute(self, context: Context) -> None:
impersonation_chain=self.impersonation_chain,
)

if self.objects:
if self.objects is not None:
objects = self.objects
else:
objects = hook.list(bucket_name=self.bucket_name, prefix=self.prefix)
Expand Down
8 changes: 8 additions & 0 deletions tests/providers/google/cloud/operators/test_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ def test_delete_objects(self, mock_hook):
any_order=True,
)

@mock.patch("airflow.providers.google.cloud.operators.gcs.GCSHook")
def test_delete_empty_list_of_objects(self, mock_hook):
operator = GCSDeleteObjectsOperator(task_id=TASK_ID, bucket_name=TEST_BUCKET, objects=[])

operator.execute(None)
mock_hook.return_value.list.assert_not_called()
mock_hook.return_value.delete.assert_not_called()

@mock.patch("airflow.providers.google.cloud.operators.gcs.GCSHook")
def test_delete_prefix(self, mock_hook):
mock_hook.return_value.list.return_value = MOCK_FILES[1:4]
Expand Down

0 comments on commit e7587b3

Please sign in to comment.