Skip to content

DynamoDB Streams: omit empty OldImage/NewImage from stream records#9821

Open
JackDanger wants to merge 2 commits intogetmoto:masterfrom
JackDanger:fix/dynamodbstreams-omit-empty-images
Open

DynamoDB Streams: omit empty OldImage/NewImage from stream records#9821
JackDanger wants to merge 2 commits intogetmoto:masterfrom
JackDanger:fix/dynamodbstreams-omit-empty-images

Conversation

@JackDanger
Copy link
Collaborator

@JackDanger JackDanger commented Mar 6, 2026

Fixes stream records to omit OldImage/NewImage when those images don't exist, matching real AWS behavior.

  • INSERT: OldImage key absent (was {})
  • REMOVE: NewImage key absent (was {})
  • MODIFY: no change

Consumers that check 'OldImage' in record['dynamodb'] were incorrectly seeing the key on INSERT events.

Fix: two and x is not None guards in StreamRecord.__init__().

AWS DynamoDB Streams does not include OldImage or NewImage keys in
stream records when the corresponding item does not exist:

- INSERT events: no OldImage (there was no previous item)
- REMOVE events: no NewImage (the item was deleted)

Previously, Moto included these keys as empty dicts (e.g. OldImage: {}
on INSERT), which doesn't match AWS behavior. Downstream consumers that
check for the presence of these keys (e.g. `if 'OldImage' in record`)
would incorrectly detect them as present.

The fix adds `and new is not None` / `and old is not None` guards to
the StreamRecord constructor so empty images are omitted entirely.
JackDanger added a commit to robotocore/robotocore that referenced this pull request Mar 6, 2026
DynamoDB Streams records incorrectly include empty OldImage/NewImage
keys (e.g. OldImage: {} on INSERT). Fix submitted upstream as
getmoto/moto#9821. Using local vendor/moto with the fix applied.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
JackDanger added a commit to robotocore/robotocore that referenced this pull request Mar 6, 2026
…w docs

- vendor/moto points to fix/dynamodbstreams-omit-empty-images branch
  (getmoto/moto#9821) which fixes empty OldImage/NewImage on stream records
- CLAUDE.md: add parallel worktree, CLI tooling, and subagent workflow docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
JackDanger added a commit to robotocore/robotocore that referenced this pull request Mar 7, 2026
DynamoDB Streams records incorrectly include empty OldImage/NewImage
keys (e.g. OldImage: {} on INSERT). Fix submitted upstream as
getmoto/moto#9821. Using local vendor/moto with the fix applied.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
JackDanger added a commit to robotocore/robotocore that referenced this pull request Mar 7, 2026
…w docs

- vendor/moto points to fix/dynamodbstreams-omit-empty-images branch
  (getmoto/moto#9821) which fixes empty OldImage/NewImage on stream records
- CLAUDE.md: add parallel worktree, CLI tooling, and subagent workflow docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant