Skip to content

Conversation

@Samk13
Copy link
Member

@Samk13 Samk13 commented May 2, 2024

❤️ Thank you for your contribution!

Description

Note:

A decision should be made whether to keep naive datetime objects or switch to timezone-aware datetimes.
Using timezone-aware objects like datetime.now(timezone.utc) ensures future compatibility and avoids the upcoming deprecation of datetime.utcnow().
For now, this PR performs a drop-in replacement with datetime.now(timezone.utc).replace(tzinfo=None) to retain compatibility with the existing naive datetime usage,
without altering the current behavior or implementation. Future revisions should consider full timezone awareness for better clarity and accuracy in time handling.

>>> from datetime import datetime, timezone
>>> print(datetime.now(timezone.utc))
2024-10-01 12:25:56.239591+00:00
>>> print(datetime.utcnow())
<stdin>:1: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
2024-10-01 12:26:08.612555
>>> print(datetime.now(timezone.utc).replace(tzinfo=None))
2024-10-01 12:27:28.583477

Once approved, we can proceed with updating the remaining packages.

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Frontend

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

@Samk13 Samk13 force-pushed the remove-deprecated-utcnow branch 2 times, most recently from f1780d7 to e570fd3 Compare October 14, 2024 21:50
…ne.utc)

* Updated datetime.utcnow() to datetime.now(timezone.utc) following its deprecated since version 3.12.
* See <https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow>
* A decision should be made whether to keep naive datetime objects or switch to timezone-aware datetimes.
@Samk13 Samk13 force-pushed the remove-deprecated-utcnow branch from e570fd3 to 08c8e60 Compare October 14, 2024 21:53
@carlinmack carlinmack added this to vNext Mar 26, 2025
@carlinmack carlinmack moved this to Triage in vNext Mar 26, 2025
@max-moser max-moser moved this from Triage to 📋 To discuss in vNext Mar 29, 2025
@max-moser
Copy link
Contributor

this seems similar to inveniosoftware/invenio-records#323
@utnapischtim told me that there were some issues encountered with jobs/celery tasks with simple replacement of utcnow() calls due to mismatches in the DB[1] - there's a PR open to address this also on a DB level: inveniosoftware/invenio-db#179

i moved it to "to discuss" for now

[1] not sure if that actually also applies here since the tz info gets stripped?

@ntarocco ntarocco removed this from PR Community Jul 29, 2025
@utnapischtim
Copy link
Contributor

super seeded by #533

@github-project-automation github-project-automation bot moved this from 📋 To discuss to To release 🤖 in vNext Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To release 🤖

Development

Successfully merging this pull request may close these issues.

3 participants