-
Notifications
You must be signed in to change notification settings - Fork 939
get or onValue with onlyOnce: true after a update operation to a path with listener attached returns the data out of date #8810
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
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
Hi @Dric0, I wasn't able to reproduce this given the code snippets you're provided. Is there a chance that you can create a minimal reproducible test case that exhibits this behavior? Thanks! |
Hi @DellaBitta, |
Hi @Dric0, Great news! I'll leave this open and it will auto close in 2 weeks. In the meantime if you encounter the problem again then let us know here and it will keep the ticket open. Thanks! |
Hello @DellaBitta,
And we perform write/read operations on a field under |
@Dric0, thanks for providing the MCVE, and apologies for the delayed response. I was able to replicate the behavior using your example. After modifying your code, it now works as intended. Here’s what I changed:
From what I observed in the original code, the initial listener returns no nodes. As a result, you wouldn’t be able to listen for any updates since there is no nodes to listen to. However, with the updated code, every update is successfully logged using To address this, could you modify the listener to return the initial snapshot that includes the initial data e.g. lower the value of the startAt condition to include the data or make the initial value to be in between the startAt and endAt condition? Let me know if you're still experiencing any issues, and please share the logs, code changes, and steps to reproduce the problem. |
Hey @jbalidiong, thanks for replying The problem is when a update operation was made to a old node outside the listener I could set the listener param to include this data, however it would not be ideal because it would fetch a lot of old data and this would be a very specific scenario when the user is changing a old node, which sometime happens. My current workaround is to fetch this old node from a cloud function to make sure it is its most up to date value. Thanks! |
I'm still not sure I'm following what we're expecting to see. I tried to simplify your example because there's a lot going on in there. This is what I got as a minimal repro - this is a single file with nothing else needed. I tried to copy the logic you have in the firebase quickstart sample repo, let me know if I'm missing anything. I do notice that in that repro, you initially populated fields named "value" and "date" and then updated fields named "paymentValue" and "paymentDate" which I'm not sure if it was intentional or not. I changed them to be the same name both times. I put in the comments the console log strings that I got, which I think are what's expected. Let me know if you're seeing something different or if I haven't called all the correct operations in the right order. From what you are saying I would expect the "get" operation to return something incorrect (value: 2), but I'm not seeing that I also tried a variation where I added a third entry ("id3") with a date inside the range. This is logged in the I also tried putting a 1s delay between various steps and it didn't result in anything.
|
@hsubox76 Sorry about the messy repo provided
Following this order of events, the |
Operating System
Ubuntu 20.04.6 LTS
Environment (if applicable)
Chrome Version 133.0.6943.126
Firebase SDK Version
11.3.1
Firebase SDK Product(s)
Database
Project Tooling
React app with Webpack
Detailed Problem Description
I have a listener attached to a specific path, which works as expected. At some point in my application, I need to read from a specific node that it is under the path with the listener attached, right after I updated this node. The data returned is not up to date, being returned the values as the write operation never happened. If I set some delay, like 3 seconds for example, sometimes the returned data from get() works as expected.
Steps and code to reproduce issue
Create a listener to path:
Later, perform a update to a node under the path being listened to:
And then, get the value from the precious path with its updated values:
Or using onValue:
The value returned from the read operation is out of date, making it looks like the write operation never happened, however the values are successfully written to the database
The text was updated successfully, but these errors were encountered: