Skip to content

handle ignoreUndefinedProperties in set(merge: true) #4347

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

Merged
merged 4 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-cars-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/firestore': patch
---

handle `ignoreUndefinedProperties` in `set({ merge: true })`. Previously this would behave as if the undefined value were `FieldValue.delete()`, which wasn't intended.
7 changes: 5 additions & 2 deletions packages/firestore/src/api/user_data_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,11 @@ export function parseData(
// context.fieldMask and we return null as our parsing result.
parseSentinelFieldValue(input, context);
return null;
} else if (input === undefined && context.ignoreUndefinedProperties) {
// If the input is undefined it can never participate in the fieldMask, so
// don't handle this below. If `ignoreUndefinedProperties` is false,
// `parseScalarValue` will reject an undefined value.
return null;
} else {
// If context.path is null we are inside an array and we don't support
// field mask paths more granular than the top-level array.
Expand Down Expand Up @@ -896,8 +901,6 @@ function parseScalarValue(
value._key.path
)
};
} else if (value === undefined && context.ignoreUndefinedProperties) {
return null;
} else {
throw context.createError(
`Unsupported field value: ${valueDescription(value)}`
Expand Down
9 changes: 9 additions & 0 deletions packages/firestore/test/integration/api/fields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ apiDescribe('`undefined` properties', (persistence: boolean) => {
});
});

it('are ignored in set({ merge: true })', () => {
return withTestDocAndSettings(persistence, settings, async doc => {
await doc.set({ foo: 'foo', bar: 'unchanged' });
await doc.set({ foo: 'foo', bar: undefined }, { merge: true });
const docSnap = await doc.get();
expect(docSnap.data()).to.deep.equal({ foo: 'foo', bar: 'unchanged' });
});
});

it('are ignored in update()', () => {
return withTestDocAndSettings(persistence, settings, async doc => {
await doc.set({});
Expand Down