fix: use timezone-aware datetimes in expiry calculation#2378
fix: use timezone-aware datetimes in expiry calculation#2378tonyandrewmeyer merged 6 commits intocanonical:mainfrom
Conversation
9be875b to
bf84978
Compare
Use `datetime.datetime.now(tz=datetime.timezone.utc)` in `_calculate_expiry()` and `datetime.datetime.fromtimestamp(..., tz=datetime.timezone.utc)` in `Container._build_fileinfo()` so that the resulting datetimes carry UTC timezone information. Naive datetimes are problematic because `datetime.isoformat()` omits the timezone suffix, producing strings that do not conform to RFC 3339 as expected by Juju. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bf84978 to
7a0e393
Compare
james-garner-canonical
left a comment
There was a problem hiding this comment.
The _calculate_expiry change seems correct.
Does this fix an active bug or one that we'd hit with a future Juju release? The PR description isn't clear, e.g.
Juju expects RFC 3339 timestamps with timezone information.
Implies that our timezone-naive timezones might be being rejected or treated oddly by Juju (perhaps it treats timestamps without timezone info as UTC, which will be incorrect in most timezones?).
The _build_fileinfo change appears to be a no-op (see comment), but is more correct, so that one doesn't need discussion.
dimaqq
left a comment
There was a problem hiding this comment.
The change looks solid.
I'm curious how come this was not an issue until now.
Also, please validate that some old Juju, like 2.9.x honours the new timestamps. I'd assume that Juju did from the get-go, being coded in Go, but better safe than sorry.
The change is in secrets, which aren't in 2.9, so that's not something that can be validated. (The other case was internal Ops code, but has been removed as suggested elsewhere in the PR). |
Summary
_calculate_expiry()(line 539): Changeddatetime.datetime.now()todatetime.datetime.now(tz=datetime.timezone.utc)so that when a charm passes atimedeltafor secret expiry, the resulting datetime is timezone-aware. Previously, the naive datetime would be serialised viadatetime_to_rfc3339(which calls.isoformat()), producing a string without a timezone suffix. Juju expects RFC 3339 timestamps with timezone information.Container._build_fileinfo()(line 3047): Changeddatetime.datetime.fromtimestamp(info.st_mtime)todatetime.datetime.fromtimestamp(info.st_mtime, tz=datetime.timezone.utc)so thatFileInfo.last_modifiedcarries UTC timezone information rather than being a naive datetime in the local timezone.Both fixes ensure that datetimes produced by these functions include explicit UTC timezone data, which is necessary for correct RFC 3339 serialisation and consistent behaviour across different host timezone configurations.
🤖 Generated with Claude Code but owned by me.