[PR #3416] feat: Deprecate datetime.utcnow() in favor of datetime.now(timezone.utc).replace(tzinfo=None) for better timezone handling (#3408) #24120

Closed
opened 2026-02-21 20:22:24 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/3416

State: closed
Merged: Yes


Description

This change replaces the deprecated datetime.utcnow() with datetime.now(timezone.utc).replace(tzinfo=None) throughout the project. This update is crucial as it ensures that all datetime objects are timezone-aware, improving the reliability of time-related data across different regions.

Fixes #3408

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update, included: Dify Document
  • Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement
  • Dependency upgrade

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Unit tests were updated with new datetime method to ensure all tests pass with the new timezone-aware objects.
  • Integration tests on the staging server to verify that the updated datetime handling works as expected across different services.

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I ran dev/reformat (backend) to appease the lint gods
  • optional I have made corresponding changes to the documentation
  • optional I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
**Original Pull Request:** https://github.com/langgenius/dify/pull/3416 **State:** closed **Merged:** Yes --- # Description This change replaces the deprecated `datetime.utcnow()` with `datetime.now(timezone.utc).replace(tzinfo=None)` throughout the project. This update is crucial as it ensures that all datetime objects are timezone-aware, improving the reliability of time-related data across different regions. Fixes #3408 ## Type of Change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [ ] Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement - [ ] Dependency upgrade # How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [x] Unit tests were updated with new datetime method to ensure all tests pass with the new timezone-aware objects. - [x] Integration tests on the staging server to verify that the updated datetime handling works as expected across different services. # Suggested Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] My changes generate no new warnings - [x] I ran `dev/reformat` (backend) to appease the lint gods - [ ] `optional` I have made corresponding changes to the documentation - [ ] `optional` I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes
yindo added the pull-request label 2026-02-21 20:22:24 -05:00
yindo closed this issue 2026-02-21 20:22:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#24120