[PR #22654] Fix/replace datetime patterns with naive utc now #30000

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

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

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

This pull request refactors the handling of datetime operations across multiple files by replacing the use of datetime.now(UTC).replace(tzinfo=None) with a new utility function, naive_utc_now(). This change standardizes the approach to generating naive UTC timestamps, improving code readability and maintainability.

Standardization of datetime handling:

  • Replaced datetime.now(UTC).replace(tzinfo=None) with naive_utc_now() in various methods across multiple files, including conversation.py, site.py, activate.py, oauth.py, data_source.py, datasets_document.py, completion.py, installed_app.py, account.py, wraps.py, and other workflow-related files. These changes ensure consistent usage of the new utility function for generating naive UTC timestamps. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]

Import updates:

This update simplifies the codebase and aligns it with best practices for handling naive UTC timestamps.

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Fixes #22598

**Original Pull Request:** https://github.com/langgenius/dify/pull/22654 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 2. Ensure there is an associated issue and you have been assigned to it > 3. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This pull request refactors the handling of datetime operations across multiple files by replacing the use of `datetime.now(UTC).replace(tzinfo=None)` with a new utility function, `naive_utc_now()`. This change standardizes the approach to generating naive UTC timestamps, improving code readability and maintainability. ### Standardization of datetime handling: * Replaced `datetime.now(UTC).replace(tzinfo=None)` with `naive_utc_now()` in various methods across multiple files, including `conversation.py`, `site.py`, `activate.py`, `oauth.py`, `data_source.py`, `datasets_document.py`, `completion.py`, `installed_app.py`, `account.py`, `wraps.py`, and other workflow-related files. These changes ensure consistent usage of the new utility function for generating naive UTC timestamps. [[1]](diffhunk://#diff-f147a55989b85d531474b85c19672b89e5a409ae90b5fce2d9d4a3431c500581L318-R319) [[2]](diffhunk://#diff-d33379ac227ff15e6ae578d6096c6ecc1c53d46cdd699df5fb5aaeac037fb0f5L80-R81) [[3]](diffhunk://#diff-c4c4a0a1a9b52454b95191e89121fb141216c5aec7aa93fa6ec75a0bab0341f7L68-R69) [[4]](diffhunk://#diff-2a8a41310d53fdce16954c3878154db7cb547b4c9e450de77c8ea7754a52f14aL113-R114) [[5]](diffhunk://#diff-4c5898209868613bd1209fe7f8cefedbacb04cfec3ba2936faaf41e7dd573fceL91-R92) [[6]](diffhunk://#diff-dc15435cf42211893f559907db1fab2da53a45fdd3a4874939056e6613be100eL753-R754) [[7]](diffhunk://#diff-9fed37230d3aff4c590c3c7e9d097a7261a941cd85283e47acb89beca9cd7a68L54-R55) [[8]](diffhunk://#diff-80fa8261e02cd706dff1f9508c305cf892bc8dfb0c66e287a5d7b1bb90d54991L125-R126) [[9]](diffhunk://#diff-60164a5c3cd72edc72d70f32df127c3665dd1ea9f130c69208d2d0367ce6baa9L83-R92) [[10]](diffhunk://#diff-98851164ab4cff43f965fcf769bffe8b86c7425baef6159b304f479bfa5cf6f7L259-R260) [[11]](diffhunk://#diff-4809ea9603ea0ac78bf588cf08a8b4e8f0e9a4e4027b2aa3c21ede14b06bb10aL187-R188) [[12]](diffhunk://#diff-59653298270ee2cdae762da5f90c459bca32e8943dfff3d9bcc1bb2cf0857fc1L74-R74) [[13]](diffhunk://#diff-59653298270ee2cdae762da5f90c459bca32e8943dfff3d9bcc1bb2cf0857fc1L359-R359) ### Import updates: * Added `from libs.datetime_utils import naive_utc_now` to all affected files to include the new utility function. This ensures that the function is available wherever datetime operations are updated. [[1]](diffhunk://#diff-f147a55989b85d531474b85c19672b89e5a409ae90b5fce2d9d4a3431c500581R22) [[2]](diffhunk://#diff-d33379ac227ff15e6ae578d6096c6ecc1c53d46cdd699df5fb5aaeac037fb0f5R13) [[3]](diffhunk://#diff-c4c4a0a1a9b52454b95191e89121fb141216c5aec7aa93fa6ec75a0bab0341f7R10) [[4]](diffhunk://#diff-2a8a41310d53fdce16954c3878154db7cb547b4c9e450de77c8ea7754a52f14aR16) [[5]](diffhunk://#diff-4c5898209868613bd1209fe7f8cefedbacb04cfec3ba2936faaf41e7dd573fceR18) [[6]](diffhunk://#diff-dc15435cf42211893f559907db1fab2da53a45fdd3a4874939056e6613be100eR52) [[7]](diffhunk://#diff-9fed37230d3aff4c590c3c7e9d097a7261a941cd85283e47acb89beca9cd7a68R21) [[8]](diffhunk://#diff-80fa8261e02cd706dff1f9508c305cf892bc8dfb0c66e287a5d7b1bb90d54991R16) [[9]](diffhunk://#diff-60164a5c3cd72edc72d70f32df127c3665dd1ea9f130c69208d2d0367ce6baa9R38) [[10]](diffhunk://#diff-98851164ab4cff43f965fcf769bffe8b86c7425baef6159b304f479bfa5cf6f7R18) [[11]](diffhunk://#diff-50bf05fd90dc101d7f4c730f5cd6ba5f9c2328c29c449dcea29cd4d364977d99R10) [[12]](diffhunk://#diff-4809ea9603ea0ac78bf588cf08a8b4e8f0e9a4e4027b2aa3c21ede14b06bb10aR28) [[13]](diffhunk://#diff-f7601f9c5a884f17f549e8fd6757a8081fa1db67d7d762fa4360111e8b1881d2R15-R16) [[14]](diffhunk://#diff-291718cdb41facfe3cdbd80662f6da9e46448ec4518badfb0cf2d1b14122ed07R9) [[15]](diffhunk://#diff-8ae068fda35f58c8c9f8eaa0a4d0e1fc1248da6010749600ad387a3263eb2abdR15) [[16]](diffhunk://#diff-4d5e0d088f54c1785cd0af298ae7201b49fa3e2975f16a804a760ba245d222d2R14) [[17]](diffhunk://#diff-1253f519c0ba24ced3111a981ed8905dd8b917df43015eb0bfde1ee56c9d3623R14) This update simplifies the codebase and aligns it with best practices for handling naive UTC timestamps. ## Screenshots | Before | After | |--------|-------| | ... | ... | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods Fixes #22598
yindo added the pull-request label 2026-02-21 20:46:39 -05:00
yindo closed this issue 2026-02-21 20:46:39 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30000