saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.15k stars 5.48k forks source link

[TECH DEBT] datetime.datetime.utcnow() is deprecated in Python 3.12 #65604

Open marmarek opened 11 months ago

marmarek commented 11 months ago

Description of the tech debt to be addressed, include links and screenshots

Using salt-ssh results in the following warning:

/usr/lib/python3.12/site-packages/salt/utils/jid.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).

Versions Report

(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)

This is salt-ssh called from/to Fedora 39

Salt Version:
          Salt: 3006.4

Python Version:
        Python: 3.12.0 (main, Oct  2 2023, 00:00:00) [GCC 13.2.1 20230918 (Red Hat 13.2.1-3)]

Dependency Versions:
          cffi: 1.15.1
      cherrypy: Not Installed
      dateutil: 2.8.2
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.2
       libgit2: Not Installed
  looseversion: 1.3.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.5
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 23.1
     pycparser: 2.20
      pycrypto: Not Installed
  pycryptodome: 3.19.0
        pygit2: Not Installed
  python-gnupg: Not Installed
        PyYAML: 6.0.1
         PyZMQ: 25.1.0
        relenv: Not Installed
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 6.3.3
           ZMQ: 4.3.4

System Versions:
          dist: fedora 39 
        locale: utf-8
       machine: x86_64
       release: 6.5.10-1.qubes.fc37.x86_64
        system: Linux
       version: Fedora Linux 39 
s0undt3ch commented 11 months ago

This should be fairly trivial to fix

from datetime import datetime, timezone

Then, every occurrence of:

datetime.utcnow()

Should get replaced by:

datetime.now(tz=timezone.utc)

We'd love to get a PR addressing this :grin:

gabrielrosendo commented 8 months ago

Is this open?