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

8.6.8 breaks Timestamp support for Firestore Emulator #5047

Closed
jirizavadil opened this issue Jun 18, 2021 · 21 comments · Fixed by #5147
Closed

8.6.8 breaks Timestamp support for Firestore Emulator #5047

jirizavadil opened this issue Jun 18, 2021 · 21 comments · Fixed by #5147
Assignees
Labels

Comments

@jirizavadil
Copy link

  • Operating System version: MacOS 11.4
  • Browser version: Google Chrome 91.0.4472.106 (Official Build) (x86_64)
  • Firebase SDK version: 8.6.8
  • Firebase tools version: 9.13.1
  • Firebase Product: firestore

Steps to reproduce:

  • update firebase to 8.6.8
  • use firestore emulator
  • write/read from firestore
  • XHRs pending for 45s and then get cancelled

I've spent over 3 hours trying to replicate this in a new project, but unsuccessfuly. In the current project i could only try emulators, not cloud environment, as i only have production cloud env at this time.

Last version that doesn't introduce any bugs for me is 8.4.0

@looptheloop88 looptheloop88 added the testing-sdk testing with emulator label Jun 18, 2021
@looptheloop88
Copy link

Hi @jirizavadil, thanks for the report. I tried replicating the issue, but I wasn't able to. I used the same SDK version and Firebase tools, but the test app was able to read and write data from Firestore database.

If I can replicate the issue, I can have a better look into it. Please share a minimal, but complete sample of a project that I can run locally. Also, you may enable Firestore debugging firebase.firestore.setLogLevel("debug"); and share with us the logs.

@mandalornl
Copy link

I think I may have the same issue, but I've managed to isolate the problem. It seems Timestamp is being the culprit here, when using it during a DocumentReference update and in conjuction with the Firestore emulator. At least in my case.

Just follow README.md in the sample code below.

https://github.com/mandalornl/firebase-8.6.8-test

I hope this helps!

@jsakas
Copy link

jsakas commented Jun 24, 2021

I spend most of my day yesterday trying to debug an issue which I believe might be related to this. In my case, using snap.ref.update() was updating the local db, but failing to update the emulated DB. Using database.doc().update() seemed to work fine. Spent hours trying to debug and create a repro unsuccessfully. Downgrading to v8.6.1 for now.

@google-oss-bot
Copy link
Contributor

Hey @jirizavadil. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@mandalornl
Copy link

I think I may have the same issue, but I've managed to isolate the problem. [...]

I would like to add that it's broken from >= 8.6.3 and not related to 8.6.8 only.

Also notice the difference between the timestampValue values:

Firebase <= 8.6.2

{
  "update": {
    "name": "projects/sometest-78e8d/databases/(default)/documents/test/CBVTnjvUzfraWgCuuynB",
    "fields": {
      "updatedAt": {
        "timestampValue": "2021-07-02T07:24:58.654000000Z"
      }
    }
  },
  "updateMask": {
    "fieldPaths": [
      "updatedAt"
    ]
  },
  "currentDocument": {
    "exists": true
  }
}
Firebase >= 8.6.3

{
  "update": {
    "name": "projects/sometest-78e8d/databases/(default)/documents/test/eUikl3S7Bt6d4AxTq0aS",
    "fields": {
      "updatedAt": {
        "timestampValue": {
          "seconds": 1625210353,
          "nanos": 166000000
        }
      }
    }
  },
  "updateMask": {
    "fieldPaths": [
      "updatedAt"
    ]
  },
  "currentDocument": {
    "exists": true
  }
}

@jirizavadil
Copy link
Author

@looptheloop88 here it is. Thanks to @mandalornl, i've been able to boil it down to a reproducible sample:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Welcome to Firebase Hosting</title>

    <script defer src="/__/firebase/8.7.0/firebase-app.js"></script>
    <script defer src="/__/firebase/8.7.0/firebase-firestore.js"></script>
    <script defer src="/__/firebase/init.js?useEmulator=true"></script>
  </head>
  <body>
    <script>
      document.addEventListener("DOMContentLoaded", async function () {

        let db = firebase.firestore()
        db.useEmulator("localhost", 8432)

        var laRef = db.collection("cities").doc("LA")

        await laRef.set({
          created: new Date()
        })

        // WORKS
        await laRef.update({
          tralala1: true,
          updated1: firebase.firestore.FieldValue.serverTimestamp()
        })

        // DOES NOTHING
        await laRef.update({
          tralala2: true,
          updated2: new Date()
        })
      })
    </script>
  </body>
</html>

I've tested many versions with this result:
works: 8.4.0, 8.4.1, 8.4.2, 8.4.3, 8.5.0, 8.6.0, 8.6.1, 8.6.2
broken: 8.6.3, 8.6.4, 8.6.5, 8.6.7, 8.6.8, 8.7.0

@looptheloop88
Copy link

Hi @jirizavadil and @mandalornl, I was able to replicate the issue using the sample projects that you've shared with us. Let me bring this matter to the attention of our engineers here.

@dconeybe dconeybe self-assigned this Jul 8, 2021
@schmidt-sebastian schmidt-sebastian changed the title 8.6.8 breaks all network requests to firestore 8.6.8 breaks all network requests to firestore emulator Jul 13, 2021
@schmidt-sebastian schmidt-sebastian changed the title 8.6.8 breaks all network requests to firestore emulator 8.6.8 breaks Timestamp support for Firestore Emulator Jul 13, 2021
@schmidt-sebastian
Copy link
Contributor

This broke with #4933, since the call here converts the timestamp to JSON (it should be a string).

Will be fixed next week.

@silviokucz
Copy link

silviokucz commented Jul 28, 2021

This issue is still happening. Using the emulator, when I try changing the data in a timestamp field, it seems like the change took but when I refresh the page it still shows the old timestamp. No entries in the log!
I have firebase version 9.16.0

@schmidt-sebastian
Copy link
Contributor

Do you have persistence enabled? I wonder if these documents are read from cache.

You should be able to see logs from the Firestore SDK itself (call firebase.firestore.setLogLevel('debug')).

@silviokucz
Copy link

This is how I start the emulator:
"npm run build:watch && firebase emulators:start --inspect-functions --export-on-exit c:\tmp\firebase --import c:\tmp\firebase"

Is there a way to set the log level using the CLI?

@schmidt-sebastian
Copy link
Contributor

No - this would be a line you need to add to your Web or Node app.

@silviokucz
Copy link

Well, I'm not sure how to do that on the functions side, is there an example?
where do i import firebase from?

I have this but doesn't compile:.
import * as functions from 'firebase-functions'
...
functions.firestore.setLogLevel('debug')

(should be easy for you to try on your end, do you experience the same problem?)

@silviokucz
Copy link

Update:
I was able to set debug level using this flag:
firebase --debug emulators:start --inspect-functions --export-on-exit c:\tmp\firebase --import c:\tmp\firebase
I see a lot of logs starting with [debug]
Unfortunately working with the firestore emulator and editing values doesn't generate any entries.

@schmidt-sebastian
Copy link
Contributor

Are you writing to Firestore from your function? You may have to invoke the Admin SDK directly. If you can send me a code snippet, I can modify it to enable logging.

@mandalornl
Copy link

This issue is still happening. Using the emulator, when I try changing the data in a timestamp field, it seems like the change took but when I refresh the page it still shows the old timestamp. No entries in the log!
I have firebase version 9.16.0

I want to confirm that this happens when you try to add or update a Timestamp field from an existing Document using the Firebase Emulator Suite web interface on localhost:4000. This also happend before the update in versions > 8.6.2 and < 8.8.0.

@silviokucz
Copy link

Confirmed. Using the emulator served on localhost:4000. Changing the value of a timestamp field fails silently.

@schmidt-sebastian
Copy link
Contributor

I was able to write Timestamps from the Web SDK, the Node Web SDK and the Node Admin SDK successfully.

Here is my setup: https://gist.github.com/schmidt-sebastian/59c76a6655b3556d542b90882de689bc

Can you spot a difference?

@silviokucz
Copy link

Thanks for sharing the code. Writing and reading timestamp fields using the SDK is not the issue, maybe I didn't explain well on the original post.
The issue occurs when using the emulator web UI manually.

@schmidt-sebastian
Copy link
Contributor

Ah, okay, that makes sense. Will get this fixed.

@yuchenshi
Copy link
Member

Fixed in Emulator UI in Firebase CLI v9.16.1.

@firebase firebase locked and limited conversation to collaborators Sep 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants