Edgewall Software

#13604 closed defect (fixed)

Python 3.12.0b1: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 1.6
Component: general Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Adapt to onexc of shutil.rmtree since Python 3.12 to avoid deprecation warnings.

API Changes:
Internal Changes:


The following is warned on calling parse_date with Python 3.12.

trac/util/datefmt.py:646: DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.fromtimestamp(timestamp, datetime.UTC).

See also: https://docs.python.org/3.12/library/datetime.html?highlight=deprecated#datetime.datetime.utcfromtimestamp


  • trac/util/datefmt.py

    diff --git a/trac/util/datefmt.py b/trac/util/datefmt.py
    index 80b574feb..d407b86ba 100644
    a b def parse_date(text, tzinfo=None, locale=None, hint='date'):  
    639639                    date=text, hint=formatted_hint, isohint=isohint)
    640640        raise TracError(msg, _('Invalid Date'))
    641641    # Make sure we can convert it to a timestamp and back -
    642     # utcfromtimestamp() may raise OverflowError and OSError if out of
     642    # fromtimestamp(..., utc) may raise OverflowError and OSError if out of
    643643    # range by platform C gmtime() and gmtime() failure
    644644    ts = to_timestamp(dt)
    645645    try:
    646         datetime.utcfromtimestamp(ts)
     646        datetime.fromtimestamp(ts, utc)
    647647    except (ValueError, OverflowError, OSError):
    648648        raise TracError(_('The date "%(date)s" is outside valid range. '
    649649                          'Try a date closer to present time.', date=text),

Attachments (0)

Change History (1)

comment:1 by Jun Omae, 12 months ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Fixed in [17707].

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.