Skip to content

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

@brettwillis

Description

@brettwillis

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.

https://github.com/googleapis/nodejs-firestore/blob/ac35b372faf32f093d83af18d487f1b3f23ee673/dev/src/serializer.ts#L205-L207

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.

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the Firestore API.library: nodejs-firestoreIssues transferred from another repositorypriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions