Skip to content

Commit 65d5b36

Browse files
authored
fix(lib-dynamodb): backwards compat for undefined columns (#5365)
1 parent 7d31222 commit 65d5b36

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/lib-dynamodb/src/commands/utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ const processAllKeysInObj = (obj: any, processFunc: Function, keyNodes: KeyNodes
8282
return obj.map((item) => processObj(item, processFunc, keyNodes));
8383
}
8484
return Object.entries(obj).reduce((acc, [key, value]) => {
85-
acc[key] = processObj(value, processFunc, keyNodes);
85+
const processedValue = processObj(value, processFunc, keyNodes);
86+
if (processedValue !== undefined) {
87+
acc[key] = processedValue;
88+
}
8689
return acc;
8790
}, {} as any);
8891
};

lib/lib-dynamodb/src/test/lib-dynamodb.e2e.spec.ts

+38-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ describe(DynamoDBDocument.name, () => {
5454
create: null as null | CreateTableCommandOutput,
5555
write: {} as Record<string, PutCommandOutput>,
5656
read: {} as Record<string, GetCommandOutput>,
57+
undefinedColumnWrite: null as null | PutCommandOutput,
58+
undefinedColumnRead: null as null | GetCommandOutput,
5759
batchWrite: null as null | BatchWriteCommandOutput,
5860
batchRead: null as null | BatchGetCommandOutput,
5961
transactWrite: null as null | TransactWriteCommandOutput,
@@ -354,6 +356,30 @@ describe(DynamoDBDocument.name, () => {
354356
})
355357
.catch(passError);
356358

359+
log.undefinedColumnWrite = await doc
360+
.put({
361+
TableName,
362+
Item: {
363+
id: "undefinedColumns",
364+
A: "A",
365+
B: undefined,
366+
C: "C",
367+
D: undefined,
368+
E: "E",
369+
},
370+
})
371+
.catch(passError);
372+
373+
log.undefinedColumnRead = await doc
374+
.get({
375+
TableName,
376+
Key: {
377+
id: "undefinedColumns",
378+
},
379+
ConsistentRead: true,
380+
})
381+
.catch(passError);
382+
357383
for (const [id, value] of [["1", data as any], ...Object.entries(data)]) {
358384
log.update[id] = await doc
359385
.update({
@@ -446,7 +472,7 @@ describe(DynamoDBDocument.name, () => {
446472
// to report the table name
447473
});
448474

449-
it("describes the test table tables", async () => {
475+
it("describes the test table", async () => {
450476
if (log.describe) {
451477
expect(log.describe?.Table?.TableName).toEqual(TableName);
452478
}
@@ -462,6 +488,17 @@ describe(DynamoDBDocument.name, () => {
462488
}
463489
});
464490

491+
it("ignores undefined column values for backwards compatibility", async () => {
492+
throwIfError(log.undefinedColumnWrite);
493+
494+
expect(log.undefinedColumnRead?.Item).toEqual({
495+
id: "undefinedColumns",
496+
A: "A",
497+
C: "C",
498+
E: "E",
499+
});
500+
});
501+
465502
it("can batch write", async () => {
466503
throwIfError(log.batchWrite);
467504
});

0 commit comments

Comments
 (0)