Skip to content

fix: replace deprecated datetime.utcnow() with timezone-aware now()#7231

Open
llukito wants to merge 1 commit intomicrosoft:mainfrom
llukito:fix/replace-deprecated-utcnow
Open

fix: replace deprecated datetime.utcnow() with timezone-aware now()#7231
llukito wants to merge 1 commit intomicrosoft:mainfrom
llukito:fix/replace-deprecated-utcnow

Conversation

@llukito
Copy link

@llukito llukito commented Feb 13, 2026

Description

This PR fixes DeprecationWarnings caused by datetime.utcnow() (deprecated in Python 3.12).

It replaces all instances of datetime.utcnow() with the standard, timezone-aware equivalent: datetime.now(timezone.utc).

Changes

  • File: python/packages/autogen-studio/autogenstudio/web/routes/ws.py
  • Updated imports to include timezone.
  • Replaced 5 instances of utcnow().isoformat() with now(timezone.utc).isoformat().

Impact

  • Safe: The .isoformat() output remains compatible with the frontend. It now explicitly includes the +00:00 UTC offset (e.g., 2023-10-05T14:30:00+00:00), which is compliant with ISO 8601 and correctly parsed by JavaScript clients.
  • Future-proof: Prevents potential crashes or warnings in Python 3.12+ environments.

### Summary
This PR replaces the deprecated `datetime.utcnow()` method with the recommended Python 3.12+ alternative: `datetime.now(timezone.utc)`.

### Details
- **Issue:** `datetime.utcnow()` is deprecated in Python 3.12 because it creates "naive" datetime objects that can lead to timezone-related bugs.
- **Fix:** Switched to `datetime.now(timezone.utc)`, which creates "aware" objects.
- **Impact:** This is a non-breaking change for the WebSocket API. The `.isoformat()` output now includes the explicit `+00:00` UTC offset, which is the standard for ISO 8601 and correctly handled by frontend (JavaScript/React) parsers.
- **Consistency:** Updated all 5 instances within `autogenstudio/web/routes/ws.py` and updated imports accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments