[go: nahoru, domu]

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

DataSnapshot.val() throws error for nested child which doesn't exist #1512

Closed
bezysoftware opened this issue Jan 14, 2024 · 3 comments
Closed

Comments

@bezysoftware
Copy link

Related issues

#1426 which is supposed to be fixed by #1432 which hasn't been merged yet. I am raising this issue again, because without the merge&release of the fix I do no consider it "fixed".

[REQUIRED] Version info

node: v16.15.0
firebase-functions: 4.6.0
firebase-tools: 12.4.0
firebase-admin: 10.2.0

[REQUIRED] Test case

import * as functions from 'firebase-functions';

export let test = functions
    .database
    .ref('/test/{id}')
    .onWrite((event, context) => console.log(event.after.child('nested/property').val()));

[REQUIRED] Steps to reproduce

Insert any value to realtime database at /test/123/whatever

[REQUIRED] Expected behavior

Calling event.after.child('nested/property').val()) should return null (as it does prior to v4)

[REQUIRED] Actual behavior

TypeError: Cannot read properties of null (reading 'property') at DataSnapshot.val (/workspace/node_modules/firebase-functions/lib/common/providers/database.js:104:32)

Were you able to successfully deploy your functions?

Yes, this is a runtime error.

Footnote

Since the v4 rewrote the exists() as a check to the result of val() it is also affected. And it's really not clear to me how else to check if the nested property exists.

@google-oss-bot
Copy link
Collaborator

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

@colerogers
Copy link
Contributor

@bezysoftware Apologies for the delay, just merged in the PR and it should be in the next release. Cheers

@exaby73
Copy link
exaby73 commented Feb 8, 2024

This fix is out with a new release

@exaby73 exaby73 closed this as completed Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants