Mailing List Archive

Ticket #13622: Python Bindings: traceback in datetime.timestamp()
#13622: Python Bindings: traceback in datetime.timestamp()
--------------------------------------+------------------------------
Reporter: rcrdnalor | Owner: rcrdnalor
Type: Bug Report - General | Status: assigned
Priority: minor | Milestone: 31.1
Component: Bindings - Python | Version: v31-fixes
Severity: medium | Keywords: Python timestamp
Ticket locked: 0 |
--------------------------------------+------------------------------
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

--
Ticket URL: <https://code.mythtv.org/trac/ticket/13622>
MythTV <http://www.mythtv.org>
MythTV Media Center
Re: Ticket #13622: Python Bindings: traceback in datetime.timestamp() [ In reply to ]
#13622: Python Bindings: traceback in datetime.timestamp()
----------------------------------+---------------------------
Reporter: rcrdnalor | Owner: rcrdnalor
Type: Bug Report - General | Status: assigned
Priority: minor | Milestone: 31.1
Component: Bindings - Python | Version: v31-fixes
Severity: medium | Resolution:
Keywords: Python timestamp | Ticket locked: 0
----------------------------------+---------------------------

Comment (by rcrdnalor):

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.

--
Ticket URL: <https://code.mythtv.org/trac/ticket/13622#comment:1>
MythTV <http://www.mythtv.org>
MythTV Media Center
Re: Ticket #13622: Python Bindings: traceback in datetime.timestamp() [ In reply to ]
#13622: Python Bindings: traceback in datetime.timestamp()
----------------------------------+---------------------------
Reporter: rcrdnalor | Owner: rcrdnalor
Type: Bug Report - General | Status: assigned
Priority: minor | Milestone: 31.1
Component: Bindings - Python | Version: v31-fixes
Severity: medium | Resolution:
Keywords: Python timestamp | Ticket locked: 0
----------------------------------+---------------------------

Comment (by richardfearn):

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)
}}}

--
Ticket URL: <https://code.mythtv.org/trac/ticket/13622#comment:2>
MythTV <http://www.mythtv.org>
MythTV Media Center
Re: Ticket #13622: Python Bindings: traceback in datetime.timestamp() [ In reply to ]
#13622: Python Bindings: traceback in datetime.timestamp()
----------------------------------+---------------------------
Reporter: rcrdnalor | Owner: rcrdnalor
Type: Bug Report - General | Status: closed
Priority: minor | Milestone: 31.1
Component: Bindings - Python | Version: v31-fixes
Severity: medium | Resolution: fixed
Keywords: Python timestamp | Ticket locked: 0
----------------------------------+---------------------------
Changes (by Roland Ernst <rcrernst@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"24db137ee6435ae0f1ecc51c580ef1b3d5936402/mythtv"
24db137ee/mythtv]:
{{{
#!CommitTicketReference repository="mythtv"
revision="24db137ee6435ae0f1ecc51c580ef1b3d5936402"
Python: fix timestamp calculation

Python 3.8 changed the handling of the 'datetime' class:
According release notes ("What's New In Python 3.8"):
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 caused an error in the calculation of a 'timestamp'.

Tested with python2.7, python3.6 and python3.8.
No other occurences of similar arithmetic operations identified.

Fixes #13622
}}}

--
Ticket URL: <https://code.mythtv.org/trac/ticket/13622#comment:3>
MythTV <http://www.mythtv.org>
MythTV Media Center
Re: Ticket #13622: Python Bindings: traceback in datetime.timestamp() [ In reply to ]
#13622: Python Bindings: traceback in datetime.timestamp()
----------------------------------+---------------------------
Reporter: rcrdnalor | Owner: rcrdnalor
Type: Bug Report - General | Status: closed
Priority: minor | Milestone: 31.1
Component: Bindings - Python | Version: v31-fixes
Severity: medium | Resolution: fixed
Keywords: Python timestamp | Ticket locked: 0
----------------------------------+---------------------------

Comment (by Roland Ernst <rcrernst@…>):

In [changeset:"d8ecd8fe7c85165fe3c818a6d07e7ca9472e7735/mythtv"
d8ecd8fe7/mythtv]:
{{{
#!CommitTicketReference repository="mythtv"
revision="d8ecd8fe7c85165fe3c818a6d07e7ca9472e7735"
Python: fix timestamp calculation

Python 3.8 changed the handling of the 'datetime' class:
According release notes ("What's New In Python 3.8"):
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 caused an error in the calculation of a 'timestamp'.

Tested with python2.7, python3.6 and python3.8.
No other occurences of similar arithmetic operations identified.

Fixes #13622

(cherry picked from commit 24db137ee6435ae0f1ecc51c580ef1b3d5936402)
}}}

--
Ticket URL: <https://code.mythtv.org/trac/ticket/13622#comment:4>
MythTV <http://www.mythtv.org>
MythTV Media Center