Skip to content
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

Clearing Emulator Data Does not work in datastore-mode #6902

Closed
tlatin opened this issue Mar 21, 2024 · 3 comments
Closed

Clearing Emulator Data Does not work in datastore-mode #6902

tlatin opened this issue Mar 21, 2024 · 3 comments

Comments

@tlatin
Copy link

tlatin commented Mar 21, 2024

I'm migrating from the datastore-emulator to the firestore-emulator, for local development with Google Appengine. I need to reset the database between tests. To do it, I'm making a DELETE request (per the documentation) to the URI: http://HOST:PORT/emulator/v1/projects/PROJECT_ID/databases/(default)/documents. But that request is failing, with the emulator complaining the database is not set to Firestore Mode.

[REQUIRED] Environment info

firebase-tools: Not using firebase-tools, using cloud-firestore-emulator via gcloud CLI.

Your current Google Cloud CLI version is: 469.0.0
The latest available version is: 469.0.0

...
│ Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 36.2 MiB │
│ Installed │ Cloud Firestore Emulator │ cloud-firestore-emulator │ 44.5 MiB │
...

Platform: macOS Version 14.3.1 (23D60)

[REQUIRED] Test case

Be able to clear the database when running in datastore mode

[REQUIRED] Steps to reproduce

I am starting the firestore emulator (in datastore-mode) with this CLI command (per the documentation):

   gcloud emulators firestore start --database-mode=datastore-mode --host-port=localhost:8091

make the curl request:

   curl -v -X DELETE "http://localhost:8091/emulator/v1/projects/tilegames-demo/databases/(default)/documents"

I've tried different project names, as well as "default".

[REQUIRED] Expected behavior

I expect it to clear the database for whatever project is specified, returning with a 200 OK message.

[REQUIRED] Actual behavior

I get the error:

[firestore] INFO: Exception when handling request: INVALID_ARGUMENT: Database mode not set to Firestore Mode. If using the gCloud CLI, please specify the --database-mode flag.

And the stack trace:

[firestore] INFO: Detected non-HTTP/2 connection.
[firestore] Mar 21, 2024 2:35:03 PM com.google.cloud.datastore.emulator.impl.util.WrappedStreamObserver onError
[firestore] WARNING: Operation failed: Database mode not set to Firestore Mode. If using the gCloud CLI, please specify the --database-mode flag.
[firestore] com.google.cloud.datastore.core.exception.ValidationException: Database mode not set to Firestore Mode. If using the gCloud CLI, please specify the --database-mode flag.
[firestore] 	at com.google.cloud.datastore.core.exception.ValidationException.validateAssertion(ValidationException.java:50)
[firestore] 	at com.google.cloud.datastore.emulator.impl.firestore.CloudFirestoreV1Router.getOrCreateBackend(CloudFirestoreV1Router.java:381)
[firestore] 	at com.google.cloud.datastore.emulator.impl.firestore.CloudFirestoreV1Router.clearData(CloudFirestoreV1Router.java:239)
[firestore] 	at com.google.cloud.datastore.emulator.firestore.EmulatorAuxiliaryGrpcAdapter$1.lambda$clearData$2(EmulatorAuxiliaryGrpcAdapter.java:91)
[firestore] 	at com.google.cloud.datastore.emulator.firestore.EmulatorAuxiliaryGrpcAdapter.unary(EmulatorAuxiliaryGrpcAdapter.java:52)
[firestore] 	at com.google.cloud.datastore.emulator.firestore.EmulatorAuxiliaryGrpcAdapter$1.clearData(EmulatorAuxiliaryGrpcAdapter.java:88)
[firestore] 	at com.google.firestore.emulator.v1.FirestoreEmulatorGrpc$MethodHandlers.invoke(FirestoreEmulatorGrpc.java:714)
[firestore] 	at io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener.onHalfClose(ServerCalls.java:182)
[firestore] 	at io.grpc.PartialForwardingServerCallListener.onHalfClose(PartialForwardingServerCallListener.java:35)
[firestore] 	at io.grpc.ForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:23)
[firestore] 	at io.grpc.ForwardingServerCallListener$SimpleForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:40)
[firestore] 	at io.grpc.Contexts$ContextualizedServerCallListener.onHalfClose(Contexts.java:86)
[firestore] 	at io.grpc.PartialForwardingServerCallListener.onHalfClose(PartialForwardingServerCallListener.java:35)
[firestore] 	at io.grpc.ForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:23)
[firestore] 	at io.grpc.ForwardingServerCallListener$SimpleForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:40)
[firestore] 	at io.grpc.Contexts$ContextualizedServerCallListener.onHalfClose(Contexts.java:86)
[firestore] 	at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:351)
[firestore] 	at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1HalfClosed.runInContext(ServerImpl.java:861)
[firestore] 	at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
[firestore] 	at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
[firestore] 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
[firestore] 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
[firestore] 	at java.base/java.lang.Thread.run(Thread.java:1583)
[firestore] 
[firestore] Mar 21, 2024 2:35:03 PM io.gapi.emulators.netty.HttpHandler$1 onError
[firestore] INFO: Exception when handling request: INVALID_ARGUMENT: Database mode not set to Firestore Mode. If using the gCloud CLI, please specify the --database-mode flag.```
@harshyyy21
Copy link
Contributor

Thanks for opening this! This documentation https://cloud.google.com/firestore/docs/emulator#clear_emulator_data is specifically for the Firestore Emulator in Native Mode. You can find Datastore Mode emulator documentation here :https://cloud.google.com/datastore/docs/emulator.

That said you'll notice that currently it is lacking a reset endpoint but good news is the next release of the emulator will add support for this! Please keep an eye out on the Datastore Mode emulator documentation for updates as well, thanks!

@tlatin
Copy link
Author

tlatin commented Mar 25, 2024

Is there an ETA on the next release? And can the documentation be updated to clearer?

@harshyyy21
Copy link
Contributor

The new release is out and the notes can be found here: https://cloud.google.com/sdk/docs/release-notes. To reset a running instance you can send a curl request like so: curl -X POST "http://localhost:8080/reset".

We should be able to get the updated docs out soon as well. Thanks for being patient!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants