Skip to content

fix(idempotency): stop daylight saving changes from shifting record expiry - #8915

Draft
cleissonom wants to merge 2 commits into
aws-powertools:developfrom
cleissonom:fix/idempotency-expiry-dst
Draft

cleissonom wants to merge 2 commits into
aws-powertools:developfrom
cleissonom:fix/idempotency-expiry-dst

Conversation

@cleissonom

@cleissonom cleissonom commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Issue number:
closes #8910

Summary

Changes

BasePersistenceLayer._get_expiry_timestamp adds expires_after_seconds to datetime.now(), a naive local time, and then converts the result to a Unix timestamp. When the UTC offset changes inside that window, the deadline moves by the size of the change: later when daylight saving time ends, earlier when it starts. In the hour that repeats after the clocks go back, the sum also loses fold, so a deadline computed during that hour that also falls inside it is stored an hour early. save_inprogress computes the in-progress expiry the same way.

Both now start from datetime.now(timezone.utc), so the period is added in elapsed seconds. The stored values are still Unix timestamps.

User experience

With TZ=America/New_York and expires_after_seconds=7200:

First call Before After
00:30 EDT, 2 Nov 2025, before the clocks go back Expires 10,800 s later; a retry at 7,201 s gets the cached result 7,200 s later
01:30 EST, 8 Mar 2026, before the clocks go forward Expires 3,600 s later; a retry inside the window runs the function again 7,200 s later
01:30 EST, 2 Nov 2025, in the repeated hour, 30 s left In-progress expiry 3,570 s before the call, so a concurrent request would not be blocked 30 s later

Values only change in time zones with daylight saving, around a change. In UTC, Lambda's default, they are the same as in 3.41.0. This changes behaviour as a bug fix under ADR 0006: the old values contradicted expires_after_seconds, which the docs define in seconds.

Verification

I used an AI coding assistant to write the change, the test and this description. It ran the checks below; I'll repeat them myself before marking this ready for review.

test_idempotent_function_expiry_across_daylight_saving_change calls a function decorated with idempotent_function, with the local cache, then repeats the call 7,200 and 7,201 seconds later and checks the saved in-progress expiry. It covers both changes and the repeated hour in New York, with UTC as the control. The timezone is set through TZ and time.tzset(), and now() is controlled by replacing datetime.datetime with a subclass.

On macOS arm64 with CPython 3.14.10 and locked dependencies, uv run --locked pytest --disable-socket -q "tests/functional/idempotency/_boto3/test_idempotency.py::test_idempotent_function_expiry_across_daylight_saving_change" gave 3 failed, 1 passed on develop (0bbc252e) with only the test added, and 4 passed with the change.

  • The idempotency tests pass on Python 3.10.22, 3.11.17, 3.12.15 and 3.13.15 (269 passed, 1 skipped on each).
  • make pr without lint-docs, which needs Docker (no Markdown changed): ruff, mypy, bandit, xenon and pre-commit pass, with 4,361 passed and 73 skipped. Two timing-based tests, test_data_masking_encrypt_with_json_blob and test_tracer_init, failed in some runs on import-time limits, on develop too, while the machine was under heavy load.
  • With the change, the reproduction script from Bug: Idempotency keeps a cached result an extra hour when daylight saving time ends #8910 gives the same counts with TZ=America/New_York as with TZ=UTC.

Nothing has been run against DynamoDB or Redis yet. I'll check the values written to a real DynamoDB table before marking this ready. Until a maintainer triages #8910, this stays a draft.


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.

@sonarqubecloud

Copy link
Copy Markdown

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

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: Idempotency keeps a cached result an extra hour when daylight saving time ends

1 participant