Skip to content

fix(idempotency): warn when a persistence layer is reused with a different config - #8664

Open
soujasK wants to merge 1 commit into
aws-powertools:developfrom
soujasK:fix/idempotency-shared-persistence-warning
Open

soujasK wants to merge 1 commit into
aws-powertools:developfrom
soujasK:fix/idempotency-shared-persistence-warning

Conversation

@soujasK

@soujasK soujasK commented Oct 25, 2026

Copy link
Copy Markdown

Issue number: closes #8659

Summary

Changes

As agreed in #8659 (option 1): BasePersistenceLayer.configure() only applies the config on its first call, so functions sharing a persistence layer instance silently use the first function's IdempotencyConfig. It now remembers the settings it applied and emits a PowertoolsUserWarning when it's configured again with a config whose settings differ, pointing to one persistence layer per config.

  • The comparison is on the settings the layer applies (event_key_jmespath, payload_validation_jmespath, jmespath_options, raise_on_no_idempotency_key, expires_after_seconds, use_local_cache, local_cache_max_items, hash_function), not on object identity, so @idempotent without a config (which creates a new IdempotencyConfig() per invocation) doesn't warn. lambda_context and response_hook aren't part of it since they're read per call.
  • Behaviour is otherwise unchanged: the first config still wins.
  • Docs: a warning admonition below the IdempotencyConfig options table.

Tests: one for the differing-config case (warns, first config's settings kept; fails without the change) and one checking that a new config with the same settings doesn't warn. tests/unit, tests/functional/idempotency and tests/functional/batch pass on Linux (Python 3.12), plus ruff, mypy, ty, bandit and xenon. The existing idempotency tests also pass with this warning turned into an error, so none of them reconfigure a layer with a different config.

User experience

Before: two idempotent functions sharing a persistence layer with different configs silently use the first function's settings, and can return another request's stored response.

After: the same setup emits a PowertoolsUserWarning telling you to use a separate persistence layer instance for each IdempotencyConfig.


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

@soujasK
soujasK requested a review from a team as a code owner October 25, 2026 18:33
@boring-cyborg boring-cyborg Bot added documentation Improvements or additions to documentation tests labels Oct 25, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 25, 2026
@sonarqubecloud

Copy link
Copy Markdown

@leandrodamascena leandrodamascena added this to the 3.40.0 milestone Oct 25, 2026

This branch has not been deployed

No deployments
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/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: idempotent functions sharing a persistence layer silently use the first function's IdempotencyConfig

2 participants