Skip to content

Conversation

@yupbank
Copy link
Contributor

@yupbank yupbank commented Jul 5, 2023

currently the GCSDeleteObjectsOperator operator will delete the whole bucket when accepting an empty list of objects. which is a bug. It should quietly skip when processing an empty list.


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@boring-cyborg boring-cyborg bot added area:providers provider:google Google (including GCP) related issues labels Jul 5, 2023
@potiuk potiuk merged commit e7587b3 into apache:main Jul 6, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Jul 6, 2023

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@RemyOstyn
Copy link

Hello @yupbank,

I found the same issue when using Airflow Task Group. If we forget to specify the when pulling files paths from xcoms, the objects will be an empty array between double quotes "[]" and the GCSDeleteObjectsOperator will delete the whole bucket content.

Example: (let's assume these tasks are in a task group)

list_files_from_gcs = GCSListObjectsOperator(
            task_id="list_files_from_gcs",
            bucket="my-bucket",
            match_glob=path + "/*.csv",
        )

remove_files_from_gcs = GCSDeleteObjectsOperator(
            task_id="remove_files_from_gcs",
            bucket_name="my-bucket,
            objects="{{ ti.xcom_pull('list_files_from_gcs') }}",
        )

Instead of:

list_files_from_gcs = GCSListObjectsOperator(
            task_id="list_files_from_gcs",
            bucket="my-bucket",
            match_glob=path + "/*.csv",
        )

remove_files_from_gcs = GCSDeleteObjectsOperator(
            task_id="remove_files_from_gcs",
            bucket_name="my-bucket",
            objects="{{ ti.xcom_pull('my_task_group.list_files_from_gcs') }}", // As you can see I have to specify the task group here to avoid deleting the whole bucket
        )

Is there a way to add protection when using task group?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:google Google (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants