fix: gracefully handle unknown fields in SSE optimistic record updates
When SSE events include custom fields not present in the client-side object metadata (e.g. user-defined fields on Opportunity), the computeOptimisticRecordFromInput function was throwing a fatal error that broke the entire SSE event stream processing. Since the function's for-loop already only processes known metadata fields, unknown fields in the record input are naturally skipped. Replace the throw with a console.warn so processing continues gracefully. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
549c7a613b
commit
a1b22b65e6
+25
-17
@@ -233,26 +233,34 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error if recordInput contains fields unrelated to the current objectMetadata', () => {
|
||||
it('should warn and skip unknown fields if recordInput contains fields unrelated to the current objectMetadata', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
const consoleWarnSpy = jest
|
||||
.spyOn(console, 'warn')
|
||||
.mockImplementation(() => {});
|
||||
|
||||
expect(() =>
|
||||
computeOptimisticRecordFromInput({
|
||||
currentWorkspaceMember,
|
||||
objectMetadataItems: generatedMockObjectMetadataItems,
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
recordInput: {
|
||||
unknwon: 'unknown',
|
||||
foo: 'foo',
|
||||
bar: 'bar',
|
||||
city: 'Paris',
|
||||
},
|
||||
cache,
|
||||
objectPermissionsByObjectMetadataId: {},
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Should never occur, encountered unknown fields unknwon, foo, bar in objectMetadataItem person"`,
|
||||
const result = computeOptimisticRecordFromInput({
|
||||
currentWorkspaceMember,
|
||||
objectMetadataItems: generatedMockObjectMetadataItems,
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
recordInput: {
|
||||
unknwon: 'unknown',
|
||||
foo: 'foo',
|
||||
bar: 'bar',
|
||||
city: 'Paris',
|
||||
},
|
||||
cache,
|
||||
objectPermissionsByObjectMetadataId: {},
|
||||
});
|
||||
|
||||
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('encountered unknown fields'),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
city: 'Paris',
|
||||
});
|
||||
|
||||
consoleWarnSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
+2
-2
@@ -69,8 +69,8 @@ export const computeOptimisticRecordFromInput = ({
|
||||
},
|
||||
);
|
||||
if (unknownRecordInputFields.length > 0) {
|
||||
throw new Error(
|
||||
`Should never occur, encountered unknown fields ${unknownRecordInputFields.join(', ')} in objectMetadataItem ${objectMetadataItem.nameSingular}`,
|
||||
console.warn(
|
||||
`computeOptimisticRecordFromInput: encountered unknown fields ${unknownRecordInputFields.join(', ')} in objectMetadataItem ${objectMetadataItem.nameSingular}. Skipping unknown fields.`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user