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

Nested object with all undefined fields causes entire nested chain to be omitted #1879

Open
brettwillis opened this issue Aug 9, 2023 · 1 comment
Assignees
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@brettwillis
Copy link
Contributor

Consider an operation like so:

ref.set({
  a: {
    b: {
      c: undefined
    }
})

With ignoreUndefinedProperties: true, I would have expected the result written to Firestore to be

{
  a: {
    b: {}
  }
}

However the actual result is that the entire abc nested chain is entirely omitted:

{}

Is this the intended behaviour?

I believe it is due to these lines below, which, when there are no other non-undefined fields in any of the objects, flows all the way up the chain causing the entire nested chain to be omitted.

if (isEmpty(map.mapValue!.fields!)) {
return null;
}

Essentially those lines mean than an object consisting entirely of undefined fields should be omitted (the object itself), rather than just serialised as an empty object.

Tested on @google-cloud/firestore version: 6.7.0.

@brettwillis brettwillis added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Aug 9, 2023
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Aug 9, 2023
@dconeybe dconeybe self-assigned this Aug 9, 2023
@dconeybe
Copy link
Contributor

@brettwillis Thank you for the bug report. I can confirm that this is indeed a bug, especially since it is inconsistent with the Firebase Web SDK (https://github.com/firebase/firebase-js-sdk) which behaves how you expect. I'll work on a fix and keep this issue updated with its progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants