fix: use parse_rfc3339 for datetime parsing to support Python 3.10 #2264
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Python 3.10's
datetime.fromisoformat()requires fractional seconds to be exactly 3 or 6 digits. Juju 4.0 returns timestamps with arbitrary precision (e.g.,2026-01-05T23:34:25.50029526Zwith 8 digits), causing parse failures.Changes
ops/hookcmds/_utils.py: Modifieddatetime_from_iso()to use existingparse_rfc3339fromops._private.timeconv, which handles arbitrary precision fractional seconds. Added logic to handle timestamps without timezone by assuming UTC.test/test_hookcmds.py: Added parametrized test covering edge cases: no fractional seconds, 8 digits, 5 digits, 1 digit, 9 digits (nanosecond precision), and no timezone.Example
This solution reuses existing, well-tested code from the repository rather than reimplementing datetime parsing logic.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.