danielwardega7777 opened a new pull request, #77630:
URL: https://github.com/apache/airflow/pull/77630
The Cloud Storage and Storage Transfer delete handler in the Google system
test resource cleanup CLI
(`providers/google/tests/system/google/resources_cleanup`) failed on Cloud
Asset Inventory entries: bucket deletion passed full
`projects/_/buckets/<name>` paths verbatim into `gs://` URLs without
`--project` or `--quiet`, transfer job deletion crashed on 2-segment
`transferJobs/<id>` paths and passed numeric project numbers directly to
`--project` (which `gcloud transfer jobs delete` rejects), already-deleted
transfer jobs were not skipped, and failed commands still printed `Resource
deleted!`.
This PR fixes `StorageDeleteHandler` *(depends on the shared cleanup helpers
PR)*:
- **Cloud Storage & Storage Transfer (`handlers/storage.py`):**
- Extract short bucket names for `gs://` URLs and pass `--quiet`.
- Skip `TransferJob` resources already in `DELETED` state.
- Accept `*, project_id: str | None = None` for both `_delete_bucket` and
`_delete_transfer_job`, resolve `--project` via `build_project_flag` (avoiding
numeric project numbers and `_` wildcards), and call `run_command_async(...,
check=True, ignore_not_found=True)`.
- **Unit tests (`test_storage_handler.py`):** Cover bucket and transfer job
deletion formats, numeric project and `_` wildcard fallback to configured
`project_id`, skipping `DELETED` transfer jobs, and deletion order.
### Verification
- `uv run --project providers/google pytest
providers/google/tests/unit/google/resources_cleanup/`: 95 passed.
- `breeze run mypy providers/google/tests/system/google/resources_cleanup
providers/google/tests/unit/google/resources_cleanup`: passed (`Success: no
issues found in 44 source files`).
- `ruff format --check` and `ruff check`: passed.
- **Manual side-by-side verification on a test GCP project (`main` vs. this
branch):**
- Created two temporary GCS buckets (one containing a test object) and a
Storage Transfer job, and confirmed Cloud Asset Inventory returned numeric
project numbers for all entries.
- **On `main`:** `TransferJob` deletion passed the numeric project number
to `--project` and failed (`The value of '--project' flag was set to Project
number`), leaving the job `ENABLED` while still printing `Resource deleted!`;
the `projects/_/buckets/<name>` bucket failed because `gcloud storage rm`
parsed `projects` as the bucket name, leaving the bucket alive while still
printing `Resource deleted!`; a 2-segment `transferJobs/<id>` entry crashed
with `ValueError: not enough values to unpack`.
- **On this branch:** Ordered `TransferJob` before `Bucket`, resolved the
numeric project number and `_` wildcard to `--project=<project_id>`, deleted
the transfer job (status transitioned to `DELETED`) and recursively deleted the
remaining bucket and its object (`exit 0`). Also verified already-deleted
buckets logged `Resource no longer exists.`, `state: DELETED` 2-segment
transfer jobs were skipped cleanly, and an invalid project ID raised
`CalledProcessError`.
- Verified zero temporary buckets and no active transfer jobs remained
afterward.
*(No newsfragment added—changes are limited to Google provider system-test
cleanup tooling under `providers/google/tests/`.)*
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Jetski (Gemini) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
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]