Skip to content

fix(sync): Handle timezone-naive datetimes in sync.toml (#8477)#8487

Open
vicheey wants to merge 16 commits intodevelopfrom
fix-8477
Open

fix(sync): Handle timezone-naive datetimes in sync.toml (#8477)#8487
vicheey wants to merge 16 commits intodevelopfrom
fix-8477

Conversation

@vicheey
Copy link
Contributor

@vicheey vicheey commented Dec 3, 2025

Which issue(s) does this change fix?

#8477, #8679

Why is this change necessary?

sam sync --watch crashes with TypeError: can't subtract offset-naive and offset-aware datetimes when the .aws-sam/sync.toml file contains timestamps without timezone information (missing +00:00 suffix). This breaks the watch functionality for users who have previously run sync commands, preventing them from using the auto-sync feature.

How does it address the issue?

The fix ensures all timestamps loaded from sync.toml are timezone-aware UTC by checking if tzinfo is None after parsing with datetime.fromisoformat() and adding UTC timezone if missing. This maintains consistency with how SAM CLI writes timestamps (always UTC timezone-aware) and handles both old sync.toml files (without timezone info) and new ones (with timezone info) correctly. The fix is applied in two locations in samcli/commands/sync/sync_context.py:

  1. When loading latest_infra_sync_time from the sync state
  2. When loading sync_time for each resource sync state

What side effects does this change have?

None. The change is backward compatible and only affects the internal datetime handling. All timestamps are now consistently timezone-aware UTC, which is the expected behavior throughout the sync module.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@vicheey vicheey requested a review from a team as a code owner December 3, 2025 22:39
@github-actions github-actions bot added area/sync sam sync command pr/internal labels Dec 3, 2025
@vicheey vicheey requested a review from seshubaws February 2, 2026 19:30
vicheey and others added 2 commits February 9, 2026 13:22
- Add error handling for invalid datetime strings in _parse_datetime_from_toml
- Add test case for invalid datetime format
- Remove PR/issue references from test class docstrings
seshubaws
seshubaws previously approved these changes Feb 11, 2026
bnusunny
bnusunny previously approved these changes Mar 2, 2026
@vicheey vicheey requested review from bnusunny and seshubaws March 27, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sync sam sync command pr/internal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants