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 #1426

Closed
bezysoftware opened this issue Jun 16, 2023 · 4 comments · Fixed by #1432
Closed

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

bezysoftware opened this issue Jun 16, 2023 · 4 comments · Fixed by #1432
Assignees

Comments

@bezysoftware
Copy link

bezysoftware commented Jun 16, 2023

Related issues

This is related to v4 changes here: https://github.com/firebase/firebase-functions/blame/c0fffcc47dee5cca93683f745b619c0d95cf7339/src/common/providers/database.ts#L123

[REQUIRED] Version info

node: v16.15.0
firebase-functions: 4.4.1
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.

@blidd-google
Copy link
Contributor

Hi @bezysoftware, thanks for finding this issue and bringing it to our attention. PR is out to fix the bug at #1432.

@bezysoftware
Copy link
Author

@blidd-google the PR is still not merged, is there something pending?

@inlined
Copy link
Member

inlined commented Feb 7, 2024

Sorry for the delay in release. The latest version of the SDK has this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants