Skip to content

Commit ce03ecf

Browse files
ofekrayjeskew
authored andcommitted
Fix issue when using batch operations on different classes with the same table name (awslabs#159)
* Fix itemIdentifier function itemIdentifier function always returned ":" as no items were pushed to the keyAttributes array. This caused problems with batch operations of different models using the same tableName.
1 parent e2ef398 commit ce03ecf

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

packages/dynamodb-data-mapper/src/DataMapper.spec.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -437,23 +437,28 @@ describe('DataMapper', () => {
437437
},
438438
];
439439

440+
let currentRequest = 0;
440441
for (let i = 0; i < 325; i++) {
441442
gets.push(new Item(i));
442-
expected[Math.floor(i / 100)][0].RequestItems.foo.Keys
443+
expected[currentRequest][0].RequestItems.foo.Keys
443444
.push({fizz: {N: String(i)}});
444445

445446
const response = {
446447
fizz: {N: String(i)},
447448
buzz: {BOOL: i % 2 === 0},
448449
pop: {S: 'Goes the weasel'}
449450
};
451+
450452
if (failures.has(String(i))) {
451-
responses[Math.floor(i / 100)].UnprocessedKeys.foo.Keys
453+
responses[currentRequest].UnprocessedKeys.foo.Keys
452454
.push({fizz: {N: String(i)}});
453-
responses[3].Responses.foo.push(response);
454-
} else {
455-
responses[Math.floor(i / 100)].Responses.foo
456-
.push(response);
455+
responses[currentRequest + 1].Responses.foo.push(response);
456+
}
457+
else {
458+
responses[currentRequest].Responses.foo.push(response);
459+
if (responses[currentRequest].Responses.foo.length === 99) {
460+
currentRequest++;
461+
}
457462
}
458463
}
459464

packages/dynamodb-data-mapper/src/DataMapper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ function itemIdentifier(
13391339
const keyAttributes: Array<string> = [];
13401340
for (const key of keyProperties) {
13411341
const value = marshalled[key];
1342-
`${key}=${value.B || value.N || value.S}`;
1342+
keyAttributes.push(`${key}=${value.B || value.N || value.S}`);
13431343
}
13441344

13451345
return keyAttributes.join(':');

0 commit comments

Comments
 (0)