Skip to content

fix(idempotency): use the record key for DynamoDB composite items - #8739

Merged
leandrodamascena merged 2 commits into
aws-powertools:developfrom
sumedh-aerram:fix/idempotency-dynamodb-composite-key-record-key
Nov 14, 2026
Merged

leandrodamascena merged 2 commits into
aws-powertools:developfrom
sumedh-aerram:fix/idempotency-dynamodb-composite-key-record-key

Conversation

@sumedh-aerram

Copy link
Copy Markdown
Contributor

Issue number:

closes #8724

Summary

Changes

Read DataRecord.idempotency_key from the sort key when DynamoDB uses a composite primary key. The partition key remains shared across operations; the sort key identifies the operation. This restores local-cache lookup of stored responses and gives response hooks and in-progress diagnostics the correct key.

Add public-decorator tests across simple and composite schemas, including a custom sort-key name, both conditional-write returned items and get-item fallback, both local-cache settings for hooks, cache replay without extra DynamoDB requests, and in-progress diagnostics. Update response-hook docs and its example. Existing tests and event fixtures remain unchanged. No storage schema, public signature or dependency changes are introduced.

User experience

Previously, replaying a record created elsewhere cached it under the static partition key and never found it by operation key. Hooks also reported the shared partition key. Replays now cache and report the operation's own key. Simple primary-key tables keep their existing behavior.

Verification

AI assistants (Claude and Codex) helped investigate and implement this change. Local commands were executed and output inspected during development.

  • New tests on unchanged upstream implementation: 16 failed, 8 passed (simple-key controls). With the one-line fix: all 24 passed.
  • All 24 new cases passed on Python 3.10.22, 3.11.17, 3.13.17 and 3.14.9; Python 3.12 full idempotency suite: 226 passed.
  • Python 3.12 full gate make -k pr ty: exit 0, 4026 passed, 73 skipped, 10 deselected; all 10 performance tests passed. Ruff, mypy (949 source files), ty, docs lint, security and complexity checks passed. Pre-commit hooks were also run explicitly on every changed file, including the new tests, and passed.
  • Tests use the existing API Gateway v2 event fixture, the public decorator and botocore Stubber. The issue explicitly requests these public API tests with no AWS resources needed. No live DynamoDB service was called. No cache-performance benchmark or latency claim is made.
  • Full repository gates on runtimes other than 3.12 and end-to-end AWS tests have not been run. Final committed, clean-tree make -k pr ty repeated successfully (exit 0); make test-dependencies passed all 15 Nox sessions on Python 3.12.14 with newly recreated environments. Independent review found no blocking defects and separately reran the 24 focused public-API cases successfully. The worktree remained clean. Optional broader cache/key-schema coverage was suggested; no defect was reproduced and existing tests were preserved.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

Read the idempotency key from the sort key for composite tables. Replayed records then use the actual operation key for response hooks, local cache lookups and in-progress diagnostics. Cover both conditional-write response and get-item paths through the public decorator, retaining simple-key controls.
@sumedh-aerram
sumedh-aerram requested a review from a team as a code owner November 1, 2026 21:53
@sumedh-aerram
sumedh-aerram requested a review from hjgraca November 1, 2026 21:53
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 1, 2026
@boring-cyborg boring-cyborg Bot added documentation Improvements or additions to documentation tests labels Nov 1, 2026
@leandrodamascena leandrodamascena added this to the 3.41.0 milestone Nov 1, 2026
@leandrodamascena

Copy link
Copy Markdown
Contributor

Thanks for the PR and for filling in the verification section, that helps. Heads up that the review may take a few days: this goes into 3.41.0 and I review every PR against a real service before approving, one at a time. No need to rebase or ping in the meantime, I'll come back here.

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sumedh-aerram! I looked at the one-line change and then at the tests, and the tests are what made me comfortable: simple and composite tables, custom sort key name, cache on and off, replay without hitting DynamoDB again. Ran everything on top of today's develop, all green. Goes out in 3.41.0, no need to rebase, you'll be in the release notes.

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.18%. Comparing base (1e42825) to head (8a68159).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8739   +/-   ##
========================================
  Coverage    97.18%   97.18%           
========================================
  Files          323      323           
  Lines        16562    16562           
  Branches      1497     1497           
========================================
  Hits         16096    16096           
  Misses         326      326           
  Partials       140      140           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena
leandrodamascena merged commit ebfc9f0 into aws-powertools:develop Nov 14, 2026
15 checks passed
@boring-cyborg

boring-cyborg Bot commented Nov 14, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@powertools-for-aws-oss-automation

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key value

2 participants