fix(sdk/python): replace deprecated datetime.utcnow() with timezone-a…#332
Conversation
…ware alternative datetime.utcnow() is deprecated since Python 3.12 and scheduled for removal. It produces naive datetime objects with no timezone info, which causes DeprecationWarning on every test run across 5 files. Additionally, two call sites combined .isoformat() + 'Z' on a timezone-aware datetime, producing invalid ISO strings like: '2026-04-05T01:30:20.584591+00:00Z' ← double timezone suffix This caused test failures in test_vc_generator.py. Changes: - agentfield/did_manager.py: add timezone import, utcnow → now(timezone.utc) - agentfield/agent.py: utcnow → now(timezone.utc), fix isoformat+Z - agentfield/client.py: datetime.datetime.utcnow() → datetime.datetime.now(datetime.timezone.utc) - agentfield/vc_generator.py: add timezone import, utcnow → now(timezone.utc) - tests/test_vc_generator.py: add timezone import, utcnow → now(timezone.utc), fix isoformat+Z All 745 tests pass with 0 failures after this change. DeprecationWarnings reduced from 36 to 0.
Performance
✓ No regressions detected |
|
@deensaleh Thanks for the cleanup here, this is heading in the right direction. I noticed there are still a couple of Could you update those remaining registration payload timestamps to use an actual UTC-aware datetime, and add a small test around that path in Not blocking on this part, but it may also be worth using one small shared helper for outbound UTC timestamps so this does not drift across files again. |
…tion payloads Per code review feedback from @santoshkumarradha: - Add _utc_now_iso() shared helper in client.py for consistent UTC timestamp formatting across the file - Replace 4 remaining datetime.datetime.now().isoformat() + 'Z' calls in the registration payloads (last_heartbeat, registered_at) with the helper — these were producing naive local timestamps with a UTC suffix incorrectly appended - Add TestUtcNowIso test class (5 tests) covering: string type, Z suffix, valid ISO parse, no double-offset, millisecond precision All 745 tests pass.
|
Good catch — updated. Added a `_utc_now_iso()` helper in `client.py` and
replaced all 4 registration payload timestamps with it. Also added
`TestUtcNowIso` (5 tests) covering the Z suffix, valid ISO parse, no
double-offset, and millisecond precision. The other files you mentioned
(`agent_server.py`, `agent_mcp.py`) have the same pattern — happy to extend
in a follow-up PR if that's useful, but wanted to keep this one scoped to
what you flagged.
…On Sat, Apr 4, 2026 at 10:02 PM Santosh kumar ***@***.***> wrote:
*santoshkumarradha* left a comment (Agent-Field/agentfield#332)
<#332 (comment)>
@deensaleh <https://github.com/deensaleh> Thanks for the cleanup here,
this is heading in the right direction. I noticed there are still a couple
of client.py call sites building timestamps with datetime.datetime.now().isoformat()
+ "Z" for last_heartbeat and registered_at. Those are still naive local
timestamps with a UTC suffix added afterward, so the timestamp handling is
not fully consistent yet.
Could you update those remaining registration payload timestamps to use an
actual UTC-aware datetime, and add a small test around that path in
client.py? Right now the test coverage added in this PR is focused on
vc_generator.py, so the client.py registration flow still is not covered.
Not blocking on this part, but it may also be worth using one small shared
helper for outbound UTC timestamps so this does not drift across files
again.
—
Reply to this email directly, view it on GitHub
<#332 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/B7QUYRAYKM2XODL4DHRT5NT4UHSHVAVCNFSM6AAAAACXM6XONCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DCOBYGI4TENBWGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
santoshkumarradha
left a comment
There was a problem hiding this comment.
Looks good now. Thanks for following up on the remaining client.py timestamp paths and adding coverage around the UTC helper.
|
Thanks Santosh. Glad the coverage landed well. AgentField's approach to
cryptographic identity and verifiable execution trails is exactly the kind
of infrastructure the space needs — happy to contribute more as the project
grows.
…On Sun, Apr 5, 2026, 1:37 AM Santosh kumar ***@***.***> wrote:
Merged #332 <#332> into
main.
—
Reply to this email directly, view it on GitHub
<#332 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/B7QUYRFETVHXKHMOIHAIRRT4UILOLAVCNFSM6AAAAACXM6XONCVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMRUGIYDINJVGQZDENA>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
…ware alternative
datetime.utcnow() is deprecated since Python 3.12 and scheduled for removal. It produces naive datetime objects with no timezone info, which causes DeprecationWarning on every test run across 5 files.
Additionally, two call sites combined .isoformat() + 'Z' on a timezone-aware datetime, producing invalid ISO strings like:
'2026-04-05T01:30:20.584591+00:00Z' ← double timezone suffix
This caused test failures in test_vc_generator.py.
Changes:
All 745 tests pass with 0 failures after this change. DeprecationWarnings reduced from 36 to 0.
Summary
Testing
./scripts/test-all.shChecklist
CHANGELOG.md(or this change does not warrant a changelog entry).Screenshots (if UI-related)
Related issues