Skip to content

Remove deprecation warning of the utcnow function#367

Closed
wint3ria wants to merge 3 commits intorayference:mainfrom
wint3ria:patch-1
Closed

Remove deprecation warning of the utcnow function#367
wint3ria wants to merge 3 commits intorayference:mainfrom
wint3ria:patch-1

Conversation

@wint3ria
Copy link

@wint3ria wint3ria commented Jul 8, 2025

For my application I tend to create several atmospheric profiles in distributed batches, and my logs are flooded by this deprecation warning

  /[redacted]/lib/python3.12/site-packages/joseki/profiles/util.py:19: 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).
    return datetime.datetime.utcnow().replace(microsecond=0).isoformat()

This simple patch fixes the issue by using the latest API as recommended.

@wint3ria wint3ria marked this pull request as draft July 8, 2025 09:08
@leroyvn leroyvn marked this pull request as ready for review July 21, 2025 14:40
Copy link
Collaborator

@leroyvn leroyvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wint3ria, thanks for your suggestion. I however think that your proposed fix only applies to Python v3.11 and higher: you need to keep the old implementation for older versions.

So my suggestion is this: in a utility module, implement a now() function that conditionally uses the old or new interface depending on Python version. Something like:

import sys
import datetime

if sys.version_info[1] < 10:
    def now():
        return datetime.datetime.utcnow()
else:
    def now():
        return datetime.datetime.now(datetime.UTC)

@wint3ria wint3ria marked this pull request as draft July 22, 2025 07:25
@wint3ria
Copy link
Author

Thank you for the review. To streamline the work and avoid extra back and forth, I suggest to wait for me to mark the PR as ready. Unless you need this to be done within a specific deadline?

As per our last discussion about it, I couldn't find a proper backport, checking the version manually seems then to be the solution, indeed.

@leroyvn
Copy link
Collaborator

leroyvn commented Jul 22, 2025

The reason to mark the PR as ready to trigger CI, happy to switch it back to draft, of course. No deadline, no.

@leroyvn leroyvn mentioned this pull request Jul 29, 2025
@leroyvn leroyvn closed this in #371 Jul 29, 2025
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.

2 participants