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

Firestore emulator is rejecting timestamp field #3553

Closed
rtitlestad opened this issue Jul 5, 2021 · 7 comments
Closed

Firestore emulator is rejecting timestamp field #3553

rtitlestad opened this issue Jul 5, 2021 · 7 comments

Comments

@rtitlestad
Copy link

[REQUIRED] Environment info

firebase-tools: 9.14.0

Platform: Windows

[REQUIRED] Test case

index.html

<script src="https://www.gstatic.com/firebasejs/8.7.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.7.0/firebase-firestore.js"></script>

<script>
  async function demo() {
    firebase.initializeApp({ projectId: "demo-timestamp" });
    const db = firebase.firestore();
    db.useEmulator("localhost", 8080);

    const userRef = await db.collection("users").add({
      name: "test-user",
    });

    await userRef.update({ number: 123 });
    await userRef.update({ born: new Date() });
  }

  demo();
</script>

[REQUIRED] Steps to reproduce

[REQUIRED] Expected behavior

The users collection should have a single document with a born field containing a timestamp

[REQUIRED] Actual behavior

The user document is missing the born field and the following error is displayed in firestore-debug.log

Jul 05, 2021 11:48:35 AM com.google.cloud.datastore.emulator.firestore.webchannel.JsonToProtoConverter toWriteRequest
WARNING: invalid message: {"streamToken":"Mg==","writes":[{"update":{"name":"projects/demo-timestamp/databases/(default)/documents/users/OwrNOmQ9GLXW8GtvJD8o","fields":{"born":{"timestampValue":{"seconds":1625478515,"nanos":11000000}}}},"updateMask":{"fieldPaths":["born"]},"currentDocument":{"exists":true}}]}
Jul 05, 2021 11:48:35 AM com.google.net.webchannel.server.common.ChannelProcessor run
WARNING: Failed to consume the event.
java.lang.RuntimeException: com.google.protobuf.InvalidProtocolBufferException: JsonObject
	at com.google.cloud.datastore.emulator.firestore.webchannel.JsonToProtoConverter.toWriteRequest(JsonToProtoConverter.java:33)
	at com.google.cloud.datastore.emulator.firestore.webchannel.FirestoreV1WebChannelAdapter$FirestoreWriteHandler.onMessage(FirestoreV1WebChannelAdapter.java:141)
	at com.google.cloud.datastore.emulator.firestore.webchannel.FirestoreV1WebChannelAdapter$FirestoreWriteHandler.onMessage(FirestoreV1WebChannelAdapter.java:111)
	at com.google.net.webchannel.server.v8.ChannelInternalImpl.onMessage(ChannelInternalImpl.java:485)
	at com.google.net.webchannel.server.v8.ForwardChannel.deliverMessage(ForwardChannel.java:114)
	at com.google.net.webchannel.server.v8.ForwardChannel.processPendingRequest(ForwardChannel.java:93)
	at com.google.net.webchannel.server.v8.ForwardChannel.consume(ForwardChannel.java:67)
	at com.google.net.webchannel.server.v8.ForwardChannel.add(ForwardChannel.java:60)
	at com.google.net.webchannel.server.v8.ChannelInternalImpl.handleRequestParams(ChannelInternalImpl.java:260)
	at com.google.net.webchannel.server.v8.ChannelInternalImpl.processSessionRequest(ChannelInternalImpl.java:317)
	at com.google.net.webchannel.server.v8.ChannelInternalImpl.handle(ChannelInternalImpl.java:142)
	at com.google.net.webchannel.server.v8.ChannelInternalImpl.consume(ChannelInternalImpl.java:78)
	at com.google.net.webchannel.server.common.ChannelProcessor.run(ChannelProcessor.java:80)
Caused by: com.google.protobuf.InvalidProtocolBufferException: JsonObject
	at com.google.cloud.datastore.emulator.firestore.webchannel.jsonformatfork.JsonFormat$ParserImpl.merge(JsonFormat.java:1348)
	at com.google.cloud.datastore.emulator.firestore.webchannel.jsonformatfork.JsonFormat$Parser.merge(JsonFormat.java:452)
	at com.google.cloud.datastore.emulator.firestore.webchannel.JsonToProtoConverter.toWriteRequest(JsonToProtoConverter.java:30)
	... 12 more
@samtstern
Copy link
Contributor

@rtitlestad thanks for the clear report! I was able to reproduce this and confirm it's an Emulator issue (not an SDK issue).

Emulator

Screen Shot 2021-07-05 at 12 12 50 PM

Production

Screen Shot 2021-07-05 at 12 12 57 PM

@neuberoliveira
Copy link

@samtstern
Dont thought its an emulator issue, i update firebase-tools to 9.14.0 some days ago and everything are working like a charm, yesterday i update everthing to work with storage emulator too and now i realize iam getting this same error, but one thing thats weird it that in my application i got the same error, but in emulator ui http://localhost:4000/firestore that exposes a firestore instance in the console devtools it works as expected, so after an extremelly boring task i track down the bogus version of client sdk

8.2.1 Work - My Initial version
8.2.10 Work
8.3.3 Work
8.4.3 Work
8.5.0 Work
8.6.1 Work
8.6.2 Work
8.6.3 Broken
8.6.4 Broken - some sort of broken import, couldt test
8.6.5 Broken
8.6.6 Broken
8.6.7 Broken
8.6.8 Broken
8.7.0 Broken

Every version tested in emulator with firebase-tools: 9.14.0

@samtstern
Copy link
Contributor

@neuberoliveira thanks for doing all of that digging! Sounds like it's maybe an SDK issue then? Or maybe some combination of an SDK issue and an Emulator issue.

@neuberoliveira
Copy link

@samtstern i guess theres a lot of tests in sdk to work in a production environment as its the main target, as far its working, my bet is some combination of sdk and emulator, maybe more on emulator side.

would like to help, but has no idea where i start, maybe find which emulator version work with 8.6.3 client sdk could help somehow?

@rtitlestad
Copy link
Author

One thing I noticed was that it only seems to happen with update() so I switched to set() with {merge: true} as a workaround in my code

@schmidt-sebastian
Copy link
Contributor

This looks like firebase/firebase-js-sdk#5047

@samtstern
Copy link
Contributor

Thanks @schmidt-sebastian! Yes it looks like this is an SDK issue. @rtitlestad let's close this one and track it over there, since that's where the fix will happen.

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

4 participants