Firestore emulator: 'operation failed' when setting fields with hyphens in a transaction
vdlingen opened this issue · 5 comments
My colleague @merlinnot mentioned that this is the repo where we should report issue with the Firestore emulator.
We encountered an issue with the emulator when we try to set a document in a transaction with field names containing hyphens, e.g.:
const ref = firestore().collection('collection').doc('doc');
transaction.set(ref, {
'test-field': 'test-value',
});
transaction.commit();
This is properly supported in the firestore admin and client SDKs.
The emulator gives the following output:
API endpoint: http://[::1]:8080
API endpoint: http://127.0.0.1:8080
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:
export FIRESTORE_EMULATOR_HOST=[::1]:8080,127.0.0.1:8080
Dev App Server is now running.
Apr 02, 2019 8:25:12 PM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
INFO: Adding handler(s) to newly registered Channel.
Apr 02, 2019 8:25:12 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
Apr 02, 2019 8:25:14 PM com.google.cloud.datastore.emulator.impl.util.WrappedStreamObserver onError
INFO: operation failed: com/google/storage/googlesql/GoogleSQLStrings
After digging a bit deeper I noticed that there is an attempted call to com.google.storage.googlesql.GoogleSQLStrings.unescapeIdentifier()
, which is not bundled in the emulator jar so a ClassNotFoundException
is thrown.
This is an unfortunate consequence of how the emulator is packaged. Right after we build it, we go over the JAR and remove any classes that contain sensitive internal code. Unfortunately, GoogleSQLStrings
is one of those classes. Updates to document fields with certain characters in them will run into this issue.
We have a tracking bug internally (id: 112104025) to migrate off of this sensitive class, but it's a tricky refactor.
Thank you for the quick response and explanation.
Updates to document fields with certain characters in them will run into this issue.
Do you perhaps have a list of the characters that would run into this issue?
Definitely a dash (-
), e.g. test-key
.
Closing this in favor of tracking it on firebase/firebase-tools#1293
Update: I have a solution that works locally. Working towards merging it.