You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bb-distributed-table: the local mock stores items by reference and keeps any JS value, while on AWS items are marshalled by the DocumentClient (mutations leak, Date/Set/Map/NaN behave differently) #1274
I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
Which package(s) are affected?
Other (@aws-blocks/bb-distributed-table)
Describe the bug
put() in the mock validates the schema and then does this.data.set(key, item): it keeps the caller's object. get() and query() hand back that stored object (or a shallow copy of it). Two consequences:
Mutations leak in both directions. Changing a nested array or object after put() changes the stored item, and changing an item returned by get() changes what the next get() returns. On AWS each put() is a snapshot and each get() a fresh copy.
No marshalling. The item never goes through the DynamoDB DocumentClient locally, so values the DocumentClient rejects or converts survive unchanged until the dev server restarts and reloads the JSON file.
Generated inputs for put({ pk, sk, data }) followed by get() (simplest differing input first), with readValidation: 'off':
data
Local
Deployed
new Set()
ok, reads back a Set
throws (empty sets can't be marshalled)
new Map([['a', 1]]) / new Map()
reads back a Map
reads back a plain object
new Date(0), { when: new Date(0) }, new Date(NaN)
reads back a Date
throws in the marshaller
[undefined], { a: undefined }
ok
throws (removeUndefinedValues isn't set)
undefined (an optional field set to undefined)
the key is present on read
the key is absent
[ , 1] (array with a hole)
length 2
length 1
1e21, 2 ** 53, Number.MAX_VALUE, NaN, Infinity
ok, round-trips
throws in the marshaller
1e-131, 5e-324
ok
ValidationException (outside DynamoDB's number range)
-0
-0
0
an instance of a class (new Point(1)), a RegExp
reads back the instance
throws
Object.create(null) with a key
null-prototype object
plain object
1n
TypeError (from JSON.stringify)
ok, reads back the number 1
Some of these (Date, unsafe integers) are already listed in #1188 as validation gaps; the shared cause is that the mock skips the DocumentClient round trip entirely.
Expected behavior
The mock stores and returns a deep copy that went through the same conversion the AWS path uses (marshall / unmarshall from @aws-sdk/util-dynamodb with the block's marshallOptions), so mutations don't leak and unsupported values fail with the same error locally.
Reproduction steps
consttable=newDistributedTable(scope,'items',{schema: z.object({pk: z.string(),sk: z.string(),tags: z.array(z.string()),at: z.any().optional()}),key: {partitionKey: 'pk',sortKey: 'sk'},});constitem={pk: 'a',sk: '1',tags: ['x'],at: newDate(0)};awaittable.put(item);item.tags.push('changed-after-put');constback=awaittable.get({pk: 'a',sk: '1'});back?.tags;// ['x', 'changed-after-put'] locally, ['x'] deployedback?.at;// a Date locally; the put() throws on AWSback?.tags.push('changed-after-get');(awaittable.get({pk: 'a',sk: '1'}))?.tags;// includes 'changed-after-get' locallyawaittable.put({pk: 'a',sk: '2',tags: [],at: newSet()});// ok locally, throws deployed
(Verified against the mock in main at 34e758c; the deployed results are from a local-vs-deployed comparison of the same calls.)
Fixed in #1582 (92798e1), which folded this into bb-kv-store after #1453 removed bb-distributed-table. The KVStore mock now stores a marshall/unmarshall copy of every item, using the same options as the AWS DocumentClient, and hands reads a fresh copy. Changing an item after put or after a read no longer changes what the store holds, and values the DocumentClient rejects fail locally too.
Two smaller differences remain and are listed as known gaps in packages/bb-kv-store/DESIGN.md:
The local data file is JSON, so a Set or binary value reads back as a plain object after the dev server restarts.
DynamoDB's number range isn't checked locally, so a number like 1e-131 is stored by the mock but rejected on AWS.
Activity
sharonyajain commentedon Nov 18, 2026
Fixed in #1582 (92798e1), which folded this into bb-kv-store after #1453 removed bb-distributed-table. The KVStore mock now stores a marshall/unmarshall copy of every item, using the same options as the AWS DocumentClient, and hands reads a fresh copy. Changing an item after put or after a read no longer changes what the store holds, and values the DocumentClient rejects fail locally too.
Two smaller differences remain and are listed as known gaps in packages/bb-kv-store/DESIGN.md: