stub42/pytz

OverflowError with time.mktime using pytz 2021.3

wasade opened this issue · 3 comments

We are observing an unexpected OverflowError from time.mktime. So far we're only able to reproduce within Github Actions.

I'm unsure if the issue is related to pytz. However, I thought it would make sense to open an issue here first to rule it out.

A minimally reproducible example of the issue is below:

import datetime
import time
import pytz
x = pytz.timezone('US/Pacific')
y = datetime.datetime(2017,5,26,15,30,16)
z = x.localize(y)
print(time.mktime(z.timetuple()))

The code above appears to work on Python 3.9 using pytz 2021.3 on OSX 11.6.1, Centos 7.9, Ubuntu 18.04 and macos-latest in Github Actions. However, it does not appear to work within ubuntu-latest on Github Actions. In all cases, Python and pytz are being sourced by conda.

An example log of the failure can be found here. The build configuration has been minimized as to only install Python 3.9 and pytz (latest).

A passing execution, on macos-latest, can be found here.

Please let me know if additional information would be helpful. I apologize if this issue is being opened on the wrong project, and if it instead would be better for python-dev. It does appear the issue has been noted with python-dev but closed on the assumption it was related to pytz.

Thank you for your time, and all your hard work on this foundational project.

I think this probably counts as a Python bug, as it should be reproducible without pytz. z.timetuple() returns a namedtuple, and it is that result that time.mktime() considers invalid.

>>> time.mktime((2017,5,26,15,30,16,4,146,1))
1495773016.0

If the above fails in the testing environment, then the issue can happen without pytz being involved at all.

I doubt that z.timetuple() is returning a different result in the testing environment, but you will need to print the value in the log output to see if this actually might be a pytz issue and it is somehow returning something completely nonsensical (z.timetuple() is Python core, but it will rely on pytz returning sane results).

Good find!! I think that's it, see here.

I'll tickle python-dev, and cite this thread. Thank you for the quick reply!

To circle back, this has been confirmed in Python. Thank you again @stub42 for the quick reply and help reducing this to pure python.