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 when parent doesn't exist #1677

Open
bezysoftware opened this issue Mar 4, 2025 · 2 comments

Comments

@bezysoftware
Copy link

bezysoftware commented Mar 4, 2025

Related issues

#1426

This is very similar to the linked issue, the difference is when accessing a nested property on an object which is already null. E.g. item is inserted (before is null) and accessing a nested property on it via child(...).val() will throw.

Here's a PR which fixed the previous issue: https://github.com/firebase/firebase-functions/pull/1432/files#diff-624712cd6925b4446aeb1f79d621685365ed0cc876000e58e1bf729ff806f34fR123

It seems clear from the code there needs to be a check if source is null when accessing it for the first time

Image

[REQUIRED] Version info

node: 18
firebase-functions: 6.2.3
firebase-tools: 13.32.0
firebase-admin: 13.1.0

[REQUIRED] Test case

import * as functions from 'firebase-functions/v1';

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

[REQUIRED] Steps to reproduce

Insert any new value to realtime database at /test/1/anything.

[REQUIRED] Expected behavior

Call to before.child(...).val() should return null

[REQUIRED] Actual behavior

TypeError: Cannot read properties of null (reading 'anything')

Were you able to successfully deploy your functions?

Yes, but errors are thrown during runtime.

@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.

@CorieW
Copy link

CorieW commented Mar 6, 2025

Hi @bezysoftware,

Thanks for reporting this issue! We’ve received it and are reviewing it. We’ll provide updates as soon as possible.

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

No branches or pull requests

3 participants