This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Odd behavior when using datetime.timedelta under cProfile
Type: Stage:
Components: Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, BTaskaya, beaugunderson, p-ganssle, xtreak
Priority: normal Keywords:

Created on 2018-10-16 22:31 by beaugunderson, last changed 2022-04-11 14:59 by admin.

Messages (4)
msg327846 - (view) Author: Beau Gunderson (beaugunderson) Date: 2018-10-16 22:31
In chasing down a bug in my code that only manifests itself when running under cProfile I managed to find the culprit in datetime.timedelta by way of dateutil.

Here is a small repro:

https://gist.github.com/beaugunderson/68ea6424a4fdcf763ccad08e42a74974

I believe an exception should still be raised in broken() when run under cProfile, but for some reason it is not.
msg327856 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2018-10-17 04:32
Here's a simpler reproduction without involving a third party library:

>>> import cProfile
>>> from datetime import timedelta
>>> pr = cProfile.Profile()
>>> timedelta.total_seconds(-25200)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor 'total_seconds' requires a 'datetime.timedelta' object but received a 'int'
>>> pr.enable()
>>> timedelta.total_seconds(-25200)
2177366085.870893
>>> pr.disable()
>>> timedelta.total_seconds(-25200)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor 'total_seconds' requires a 'datetime.timedelta' object but received a 'int'


However, it appears fixed on master:

$ ./python
Python 3.8.0a0 (heads/master:c984d20ec8, Oct 16 2018, 20:47:49) 
[GCC 7.3.0] on linux
>>> 
>>> import cProfile
>>> from datetime import timedelta
>>> pr = cProfile.Profile()
>>> timedelta.total_seconds(-25200)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor 'total_seconds' requires a 'datetime.timedelta' object but received a 'int'
>>> pr.enable()
>>> timedelta.total_seconds(-25200)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor 'total_seconds' for 'datetime.timedelta' objects doesn't apply to 'int' object
>>> pr.disable()
>>> timedelta.total_seconds(-25200)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor 'total_seconds' requires a 'datetime.timedelta' object but received a 'int'


Doing a git bisect shows that this commit fixed the issue: https://github.com/python/cpython/pull/8300

Here's the bpo for that: https://bugs.python.org/issue34126
msg328268 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-10-22 18:24
Thanks Anthony for the details. This was fixed in master and back ported to 3.7. The fix is also released with 3.7.1 [0] which I have verified locally. So I propose closing this issue since upgrading to the latest maintenance release fixes this.

[0] https://www.python.org/downloads/release/python-371/

Thanks
msg356901 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-11-18 19:14
This bug is fixed in both 3.8 and 3.7, @p-ganssle what do you think about closing this?
History
Date User Action Args
2022-04-11 14:59:07adminsetgithub: 79185
2019-11-18 19:14:19BTaskayasetnosy: + BTaskaya
messages: + msg356901
2018-10-22 19:22:07p-gansslesetnosy: + p-ganssle
2018-10-22 18:24:59xtreaksetnosy: + xtreak
messages: + msg328268
2018-10-17 04:32:01Anthony Sottilesetnosy: + Anthony Sottile
messages: + msg327856
2018-10-16 22:31:03beaugundersoncreate