firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

Async getData() returns the value of parent node instead of the child node.

Open kahaYu opened this issue 1 year ago • 13 comments

Description

Hello!

When I call the async getData() method, it returns the snapshot of the parent, not the actual child.

Reproducing the issue

Create User node and two nodes inside of it: id, name.

  • User -- id : testId -- name: testName

Call: let userId = try! await Database.database().reference().child("User").child("id").getData().value

It returns 2 key-value pairs id="testId", name="testName". But not the id only.

Firebase SDK Version

10.17.0

Xcode Version

15.1

Installation Method

Swift Package Manager

Firebase Product(s)

Database

Targeted Platforms

iOS

Relevant Log Output

No logs.

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet

Replace this line with the contents of your Package.resolved.

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet

Replace this line with the contents of your Podfile.lock!

kahaYu avatar May 14 '24 18:05 kahaYu

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar May 14 '24 18:05 google-oss-bot

This appears to be the same issue as #12168 and #12225. I have an attempt at a fix here: https://github.com/firebase/firebase-ios-sdk/pull/12169 But in a comment on #12225 back in February, 2024 @paulb777 mentions that the issue is more involved than what my fix is solving.

We are encountering hard-to-discover bugs related to this issue, and I would love to help fixing it.

@paulb777 Would it at all be possible for you to share your investigations about the extent of this issue, so that myself or others might be able to help fixing the issue?

mortenbekditlevsen avatar May 23 '24 06:05 mortenbekditlevsen

Thanks for the reply @mortenbekditlevsen Ok, will wait for the fix, until then will get the whole bundle of data and locally grab the needed fields. Which results in more spendings on Firebase though haha

kahaYu avatar May 23 '24 09:05 kahaYu

Any update on this? This issue is causing a lot of data to be downloaded to the client.. and that cost $$$

pangia avatar Jul 25 '24 20:07 pangia

Im having the same issue, came from here: https://stackoverflow.com/questions/72439469/calling-getdata-on-firebase-databasereference-returns-the-data-for-the-parent-re

UPDATE: In case someones need it, I figure a work around:

https://stackoverflow.com/a/79178267/4017501

I don't think this is a solution at SDK level because "objective C", however the same pattern must have a version in that language, right?

cutiko avatar Nov 11 '24 15:11 cutiko

Im having the same issue, came from here: https://stackoverflow.com/questions/72439469/calling-getdata-on-firebase-databasereference-returns-the-data-for-the-parent-re

UPDATE: In case someones need it, I figure a work around:

https://stackoverflow.com/a/79178267/4017501

I don't think this is a solution at SDK level because "objective C", however the same pattern must have a version in that language, right?

Thanks for the reply @cutiko, Do you have any idea if there is a way to implement this workaround in a Flutter framework? Thanks in advance :)

pablosf1 avatar Nov 27 '24 18:11 pablosf1

Will this ever be fixed? This is a huge issue.

pangia avatar Jan 01 '25 18:01 pangia

Wow, I've been trying to report this on StackOverflow and the Firebase forums for years and getting shouted down by one particularly dismissive employee. Glad to see that it's finally been publicly acknowledged as a real issue.

jakehawken avatar Feb 07 '25 17:02 jakehawken

It's very real. I've tried fixing it myself here:

https://github.com/firebase/firebase-ios-sdk/pull/12169

I must admit that I forgot why the PR was not accepted, but I think the reason I got was that the issue was bigger than what my PR attempts to fix.

Would love to hear more details about that, because I would very much like to help fix the issue.

mortenbekditlevsen avatar Feb 07 '25 18:02 mortenbekditlevsen

Right. It's an acknowledged issue that requires a more complicated fix.

If you haven't yet, please thumbs-up the issue up top to help with prioritization.

paulb777 avatar Feb 07 '25 19:02 paulb777

Right. It's an acknowledged issue that requires a more complicated fix.

If you haven't yet, please thumbs-up the issue up top to help with prioritization.

you got it, friend 🫡

jakehawken avatar Feb 07 '25 21:02 jakehawken