firebase / firebase/firebase-tools

Bug: firebase functions:delete fails for onTaskDispatched function, attempts to create a queue

Open
#9,305 3 comments 0 reactions 0 assignees View on GitHub
api: functions reproducible triaged type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### [REQUIRED] Environment Info

- **`firebase-tools` version:** 14.19.1
- **Platform:** macOS

### [REQUIRED] Test Case

Minimal reproducible example.

### [REQUIRED] Steps to Reproduce

1. Define a simple Gen 2 `onTaskDispatched` function in `functions/index.js` **without** `taskQueueOptions`. This causes the Firebase deployer to auto-create a queue with the same name as the function.
```javascript
// functions/index.js
const { onTaskDispatched } = require("firebase-functions/v2/tasks");

exports.myTaskFunction = onTaskDispatched({
region: "us-central1",
}, (req) => {
console.log("Executed myTaskFunction");
});
```

2. Deploy this function: `firebase deploy --only functions:myTaskFunction`. This will succeed and create both the function `myTaskFunction` and a Cloud Tasks queue also named `myTaskFunction`.
3. Go to the Google Cloud Console -> Cloud Tasks and manually **delete the `myTaskFunction` queue**.
4. Wait a minute.
5. Attempt to delete the *function* using the CLI: `firebase functions:delete myTaskFunction`.

### [REQUIRED] Expected Behavior

The `firebase functions:delete` command should successfully delete the `myTaskFunction` Cloud Function and its associated resources (Cloud Run service, Eventarc trigger) without attempting to create any new resources.

### [REQUIRED] Actual Behavior

The `firebase functions:delete` command fails. It incorrectly attempts to make a `CreateQueue` API call for a queue with the same name as the function. This fails with a `400` error because the queue name existed too recently. Function cannot be deleted from CLI.

**Terminal Output:**
```
firebase functions:delete myTaskFunction
✔ You are about to delete the following Cloud Functions:
myTaskFunction(us-central1)
Are you sure? Yes
i functions: deleting Node.js 20 (2nd Gen) function myTaskFunction(us-central1)...
Request to https://cloudtasks.googleapis.com/v2/projects/PROJECT/locations/us-central1/queues/myTaskFunction?updateMask=name%2Cstate had HTTP Error: 400, The queue cannot be created because a queue with this name existed too recently.

Functions deploy had errors with the following functions:
myTaskFunction(us-central1)
```

This shows that a `delete` command is incorrectly triggering a `create` or `update` operation on a related but separate resource.

Contributor guide

Open the contributing guide

Research direction

Start with the `firebase functions:delete myTaskFunction` entry point and reproduce the case using `functions/index.js`, the Gen 2 `onTaskDispatched` function, and the listed deploy and delete commands. Trace why deletion reaches the Cloud Tasks queue operation after the queue is removed; done means the function and associated resources delete successfully without attempting to create or update a queue.

Written by the indexing model from the issue text.

Assessment

Tech stack
google-cloud, javascript, typescript
Domain
backend, cli, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.