Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#13622 closed Bug Report - General (fixed)

Python Bindings: traceback in datetime.timestamp()

Reported by: rcrdnalor Owned by: rcrdnalor
Priority: minor Milestone: 31.1
Component: Bindings - Python Version: v31-fixes
Severity: medium Keywords: Python timestamp
Cc: Ticket locked: no

Description

Using Python3.6, the following sequence works:

$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from MythTV import datetime
>>> t = datetime.now()
>>> t.timestamp()
1590160731.214045

In contrast, on Python3.8, this gives an error:

$ python3
Python 3.8.2 (default, Apr 27 2020, 15:53:34) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from MythTV import datetime
>>> t = datetime.now()
>>> t.timestamp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/local-admin/MythTV/mythservices/MythTV/utility/dt.py", line 483, in timestamp
    return ((utc_naive - utc_epoch).total_seconds())
TypeError: can't subtract offset-naive and offset-aware datetimes

Error reported on the MythTV forum: https://forum.mythtv.org/viewtopic.php?f=6&t=3793

Change History (4)

comment:1 by rcrdnalor, 5 years ago

From the Python docs: https://docs.python.org/3/whatsnew/3.8.html

Arithmetic operations between subclasses of datetime.date or datetime.datetime and datetime.timedelta objects now return an instance of the subclass, rather than the base class. This also affects the return type of operations whose implementation (directly or indirectly) uses datetime.timedelta arithmetic, such as astimezone(). (Contributed by Paul Ganssle in bpo-32417.)

Complete review of MythTV's datetime implementation needed.

comment:2 by richardfearn, 5 years ago

As a workaround, I'm doing this:

naive_datetime = mythtv_datetime.asnaiveutc()
python_datetime = datetime(naive_datetime.year, naive_datetime.month, naive_datetime.day,
                           naive_datetime.hour, naive_datetime.minute,
                           tzinfo=pytz.utc)

comment:3 by Roland Ernst <rcrernst@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 24db137ee/mythtv:

Error: Processor CommitTicketReference failed
GIT backend not available

comment:4 by Roland Ernst <rcrernst@…>, 5 years ago

In d8ecd8fe7/mythtv:

Error: Processor CommitTicketReference failed
GIT backend not available
Note: See TracTickets for help on using tickets.