Skip to content

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

Closed

Description

@belaboe

Before opening, please confirm

  • I have searched for duplicate or closed issues.
  • 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:

  1. 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.
  2. 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

const table = new DistributedTable(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' },
});

const item = { pk: 'a', sk: '1', tags: ['x'], at: new Date(0) };
await table.put(item);
item.tags.push('changed-after-put');
const back = await table.get({ pk: 'a', sk: '1' });
back?.tags;          // ['x', 'changed-after-put'] locally, ['x'] deployed
back?.at;            // a Date locally; the put() throws on AWS
back?.tags.push('changed-after-get');
(await table.get({ pk: 'a', sk: '1' }))?.tags; // includes 'changed-after-get' locally

await table.put({ pk: 'a', sk: '2', tags: [], at: new Set() }); // 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.)

Environment

  • @aws-blocks/* 0.8.0 (main at 34e758c)
  • Local: npm run dev dev server, Node 22, macOS
  • Deployed: a sandbox stack in us-east-1

Additional context

Activity

  1. sharonyajain commented on Nov 18, 2026

    @sharonyajain
    Contributor

    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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions