Skip to content

Commit 2f0aaf4

Browse files
committed
handle ignoreUndefinedProperties in set(merge: true)
Previously any field in the document would be propagated into the FieldMask regardless of whether or not it had an undefined value, which led to the client acting as if the user had passed FieldValue.delete(), which wasn't intended. Fixes googleapis/nodejs-firestore#1392 for the JS SDK.
1 parent c2bd3db commit 2f0aaf4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/firestore/src/api/user_data_reader.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,11 @@ export function parseData(
741741
} else {
742742
// If context.path is null we are inside an array and we don't support
743743
// field mask paths more granular than the top-level array.
744-
if (context.path) {
744+
//
745+
// If the input is undefined it can never participate in the fieldMask. With
746+
// `ignoreUndefinedProperties` set to false, `parseScalarValue` will reject
747+
// an undefined value.
748+
if (context.path && input !== undefined) {
745749
context.fieldMask.push(context.path);
746750
}
747751

packages/firestore/test/integration/api/fields.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,15 @@ apiDescribe('`undefined` properties', (persistence: boolean) => {
398398
});
399399
});
400400

401+
it('are ignored in set({ merge: true })', () => {
402+
return withTestDocAndSettings(persistence, settings, async doc => {
403+
await doc.set({ foo: 'foo', 'bar': 'unchanged' });
404+
await doc.set({ foo: 'foo', 'bar': undefined }, { merge: true });
405+
const docSnap = await doc.get();
406+
expect(docSnap.data()).to.deep.equal({ foo: 'foo', bar: 'unchanged' });
407+
});
408+
});
409+
401410
it('are ignored in update()', () => {
402411
return withTestDocAndSettings(persistence, settings, async doc => {
403412
await doc.set({});

0 commit comments

Comments
 (0)