fix: replace deprecated datetime.utcnow() with timezone-aware now()#7231
Open
llukito wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: replace deprecated datetime.utcnow() with timezone-aware now()#7231llukito wants to merge 1 commit intomicrosoft:mainfrom
llukito wants to merge 1 commit intomicrosoft:mainfrom
Conversation
### 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR fixes
DeprecationWarnings caused bydatetime.utcnow()(deprecated in Python 3.12).It replaces all instances of
datetime.utcnow()with the standard, timezone-aware equivalent:datetime.now(timezone.utc).Changes
python/packages/autogen-studio/autogenstudio/web/routes/ws.pytimezone.utcnow().isoformat()withnow(timezone.utc).isoformat().Impact
.isoformat()output remains compatible with the frontend. It now explicitly includes the+00:00UTC offset (e.g.,2023-10-05T14:30:00+00:00), which is compliant with ISO 8601 and correctly parsed by JavaScript clients.