-
Notifications
You must be signed in to change notification settings - Fork 926
FAILED_PRECONDITION error when committing transaction to clean Firestore Emulator #5871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@ikappaki I wasn't able to reproduce the error message that you mentioned. I got this expected error instead:
Here is the code that I used to reproduce: import { initializeApp } from "firebase/app";
import { connectFirestoreEmulator, collection, doc, getFirestore, runTransaction } from "firebase/firestore";
const firebaseConfig = {
// insert config data here
};
const app = initializeApp(firebaseConfig);
const firestore = getFirestore();
connectFirestoreEmulator(firestore, 'localhost', 8080);
const docRef = doc(collection(firestore, 'foo'));
runTransaction(firestore, (transaction): Promise<any> => {
return transaction.get(docRef)
.then((snapshot) => {
transaction.update(docRef, {'foo': 42});
});
}); (this code is published at https://github.com/dconeybe/FirestoreEmulatorTransactionFailedPreconditionIssue5871) Could you provide the full code snippet that you used to reproduce? Do you notice anything different in your code than mine? I'd like to reproduce for myself to facilitate debugging. Here is the full log:
|
Hi @dconeybe, Thanks for looking into this. I am using the Web API in from a browser in ClojureScript to invoke the transaction, thus the calls to the emulators seem to me that are performed via REST not RPC (I'm inferring this from the logs). It will take me some time to figure out how to extract the minimal possible reproducible JS code from the ClojureScript compiler output. Would you be able to perhaps provide me with a minimal setup similar to https://github.com/dconeybe/FirestoreEmulatorTransactionFailedPreconditionIssue5871 but using Web API REST calls that can be invoked from a browser instead of utilising RPC? Not sure where to start if I go down this path by myself, perhaps I should look into the firestore quickstart-js for inspiration. If I modify your example to match my code it looks like the below and it does work fine when invoked from node.js: import { initializeApp } from "firebase/app";
import { connectFirestoreEmulator, collection, doc, getFirestore, runTransaction, setLogLevel } from "firebase/firestore";
const firebaseConfig = {
// config
};
const app = initializeApp(firebaseConfig);
setLogLevel('debug');
const firestore = getFirestore();
connectFirestoreEmulator(firestore, 'localhost', 8080);
const docRef = doc(firestore, 'repl-words', 'foo');
runTransaction(firestore, (transaction): Promise<any> => {
return transaction.get(docRef)
.then((snapshot) => {
transaction.set(docRef, {'foo': 42});
});
}); log
Thanks! |
Good news, I've managed to reproduce it with your example, it is the mere presence of import { initializeApp } from "firebase/app";
import "firebase/auth";
import { connectFirestoreEmulator, collection, doc, getFirestore, runTransaction, setLogLevel } from "firebase/firestore";
const firebaseConfig = {
// ...
};
const app = initializeApp(firebaseConfig);
setLogLevel('debug');
const firestore = getFirestore();
connectFirestoreEmulator(firestore, 'localhost', 8080);
const docRef = doc(firestore, 'repl-words', 'foo');
runTransaction(firestore, (transaction): Promise<any> => {
return transaction.get(docRef)
.then((snapshot) => {
transaction.set(docRef, {'foo': 42});
});
}); log
thanks |
@ikappaki I still cannot reproduce the "the stored version (1641636454958701) does not match the required base version (0)" error, even when I add the import for What sort of authentication do you have set up in the Firestore emulator? What security rules have you configured? |
Hi @dconeybe, indeed it does not occur the first time the db is brought up, the db has to be cleared first. could you please try the following
I don't have any authentication or security rules setup. It is as plain as it can get. Thanks |
Ahh okay NOW I can reproduce. Let me dig into this a bit. |
I'm assigning this to @yuchenshi who has expertise in the Firestore emulator. Here are the results of my investigation: Here is the problematic code (hereafter referred to as
Prerequisites
Steps
Expected ResultsBoth times that the Actual Results:The first time that the
Minimal app to reproduce: https://github.com/dconeybe/FirestoreEmulatorTransactionFailedPreconditionIssue5871 |
Let me try to explain why this happens.
From the repro steps:
It would say this is an SDK bug, we should change SDK to use I would guess that prod database would behave similarly. ( Can we route this to the admin SDK them? |
@schmidt-sebastian would you mind looking at this? |
Assigning to current on-call. We should be sending a precondition of |
Any update for this? The precondition failed is causing my automated tests to error out when using |
This same scenario is a problem when using |
Hi @ehsannas, @dconeybe, @schmidt-sebastian and @yuchenshi. apologies for the wide distribution, but not sure who is supposed to be looking at this. It has been more than a year since this issue was reported and it appears there is an easy fix to apply. As mentioned by other users, the bug is still out there at large. Could someone please apply the suggested fix so as to close this issue? Thanks |
I'll get a fix out by the end of the week. |
The fix has been merged: #6550. It should be included in the next release. I'll reply back here once the release is out. I'm also going to make sure the fix is ported to Android and iOS, but I have no ETA for those fixes. |
FYI The fix has been released in Firebase JS SDK version 9.9.4 (released Sept 01, 2022): https://firebase.google.com/support/release-notes/js#version_994_-_september_1_2022 |
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
I'm getting a
FAILED_PRECONDITION
error when submitting a simple transaction withrunTransaction
to the Firestone Emulator which has no data. Error message is similar to #3977.I'm calling firebase from
ClojureScript
via the firebase npm package.Logs
produced with
firebase.firestore.setLogLevel('debug')
.Thanks
The text was updated successfully, but these errors were encountered: