firebase / firebase/firebase-admin-node

`DocumentReference.create()` keeps trying to create an already existing document, leading to a hang in functions

Offen
#2,587 18 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @cherylEnkidu Auf GitHub ansehen
api: firestore
Vorherrschende Sprache
TypeScript
Sterne
1.7k
Forks
419
Ø Merge
3 T. 10 Std.
Gemergte PRs (30 T.)
16

Beschreibung

### [READ] Step 1: Are you in the right place? ✅

### [REQUIRED] Step 2: Describe your environment

* Operating System version: `MacOS 14.5`
* Firebase Product: `functions`, `firestore`
* Node.js version: `v18.20.3`
* NPM version: `10.7.0`

### [REQUIRED] Step 3: Describe the problem

#### Steps to reproduce:
1. Create a new demo project via `firebase init`
2. Select `functions` and `firestore`
3. Run emulators through: `firebase emulators:start --inspect-functions --project demo-me`
4. Visit `http://127.0.0.1:5001/demo-me/us-central1/runMeTwice` in browser
5. Refresh

#### Relevant Code:
```json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"engines": {
"node": "18"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^12.1.0",
"firebase-functions": "^5.0.0"
},
"private": true
}
```

```js
//@ts-check
const { onRequest } = require("firebase-functions/v2/https");
const logger = require("firebase-functions/logger");
const { firestore, initializeApp } = require("firebase-admin");
const { initializeFirestore } = require("firebase-admin/firestore");

/** @type {firestore.Firestore} */
let _defaultFirestore;
function defaultFirestore() {
return _defaultFirestore ??= initializeFirestore(initializeApp(), {
preferRest: true,
})
}

exports.runMeTwice = onRequest(async (_, res) => {
try {
const doc = defaultFirestore().collection("test").doc("smt");
await doc.create({});
logger.log("Created");
} catch (error) {
logger.log(error);
} finally {
res.end();
}
});
```

### Expected behavior

The second time the function is ran, it should fail.

### Actual behavior

The first time the function is run the document is created. The second time, the function never completes.

Additionally, attaching to the node process, it seems the creation process keeps getting retried even though it should fail.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.