Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime.datetime.fromtimestamp(0, tzlocal()) throws error #82826

Closed
mzhang13 mannequin opened this issue Oct 30, 2019 · 9 comments
Closed

datetime.datetime.fromtimestamp(0, tzlocal()) throws error #82826

mzhang13 mannequin opened this issue Oct 30, 2019 · 9 comments
Labels
3.7 (EOL) end of life type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@mzhang13
Copy link
Mannequin

mzhang13 mannequin commented Oct 30, 2019

BPO 38645
Nosy @abalkin, @ammaraskar, @pganssle, @corona10, @mzhang13, @PythonCoderAS

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2019-11-01.03:11:09.212>
created_at = <Date 2019-10-30.15:07:25.514>
labels = ['3.7', 'type-crash']
title = 'datetime.datetime.fromtimestamp(0, tzlocal()) throws error'
updated_at = <Date 2019-11-01.03:11:09.206>
user = 'https://github.com/mzhang13'

bugs.python.org fields:

activity = <Date 2019-11-01.03:11:09.206>
actor = 'ammar2'
assignee = 'none'
closed = True
closed_date = <Date 2019-11-01.03:11:09.212>
closer = 'ammar2'
components = []
creation = <Date 2019-10-30.15:07:25.514>
creator = 'mzhang13'
dependencies = []
files = []
hgrepos = []
issue_num = 38645
keywords = []
message_count = 9.0
messages = ['355720', '355772', '355780', '355783', '355784', '355785', '355786', '355787', '355788']
nosy_count = 6.0
nosy_names = ['belopolsky', 'ammar2', 'p-ganssle', 'corona10', 'mzhang13', 'ThePokestarFan']
pr_nums = []
priority = 'normal'
resolution = 'third party'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'crash'
url = 'https://bugs.python.org/issue38645'
versions = ['Python 3.7']

@mzhang13
Copy link
Mannequin Author

mzhang13 mannequin commented Oct 30, 2019

Discovered this while trying to use a function in boto3. Seems like when tzlocal() is passed with a 0 to datetime.datetime.fromtimestamp(), it throws an "[Errno 22] Invalid argument" error. Using 3.7.4 via Anaconda on Windows 10, and tzlocal().tznames's local timezone for me is EST/EDT.

Can replicate through this:

import datetime
from dateutil.tz import tzlocal

print(datetime.datetime.fromtimestamp(0, tzlocal()))

@mzhang13 mzhang13 mannequin added 3.7 (EOL) end of life type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 30, 2019
@PythonCoderAS
Copy link
Mannequin

PythonCoderAS mannequin commented Oct 31, 2019

For me, it seems that dateutil is not a standard Python library module. When I run import dateutil it reports that there is no module called dateutil.

>>> import dateutil
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named dateutil

@corona10
Copy link
Member

corona10 commented Nov 1, 2019

Python 3.9.0a0 (heads/master:112f2b805b, Nov  1 2019, 10:48:20)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> utc_tzinfo = datetime.timezone.utc
>>> print(datetime.datetime.fromtimestamp(0, utc_tzinfo))
1970-01-01 00:00:00+00:00

works properly on my Linux machine.
Can you gave me which can reproduce based on stdlib library?

@mzhang13
Copy link
Mannequin Author

mzhang13 mannequin commented Nov 1, 2019

I think it might be something Windows specific; the original comment includes the version and code to reproduce.

@PythonCoderAS
Copy link
Mannequin

PythonCoderAS mannequin commented Nov 1, 2019

Can you run

>>import dateutil
>>print(repr(dateutil))

@ammaraskar
Copy link
Member

It is windows specific, but I don't think this is a dateutil bug rather than the python stdlib:

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> from dateutil.tz import tzlocal
>>> print(datetime.datetime.fromtimestamp(0, tzlocal()))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python365\lib\site-packages\dateutil\tz\_common.py", line 144, in fromutc
    return f(self, dt)
  File "D:\Python365\lib\site-packages\dateutil\tz\_common.py", line 258, in fromutc
    dt_wall = self._fromutc(dt)
  File "D:\Python365\lib\site-packages\dateutil\tz\_common.py", line 238, in _fromutc
    dtdst = enfold(dt, fold=1).dst()
  File "D:\Python365\lib\site-packages\dateutil\tz\tz.py", line 225, in dst
    if self._isdst(dt):
  File "D:\Python365\lib\site-packages\dateutil\tz\tz.py", line 288, in _isdst
    if self.is_ambiguous(dt):
  File "D:\Python365\lib\site-packages\dateutil\tz\tz.py", line 250, in is_ambiguous
    (naive_dst != self._naive_is_dst(dt - self._dst_saved)))
  File "D:\Python365\lib\site-packages\dateutil\tz\tz.py", line 254, in _naive_is_dst
    return time.localtime(timestamp + time.timezone).tm_isdst
OSError: [Errno 22] Invalid argument

As you can see, none of that backtrace is within Python, it's all inside dateutil code. More than likely they are calling time.localtime with a value of less than 0 which throws an error on Windows. (see also bpo-29097)

@ammaraskar
Copy link
Member

Err...I mean I think this is a dateutil bug rather than in the Python stdlib.

@mzhang13
Copy link
Mannequin Author

mzhang13 mannequin commented Nov 1, 2019

Yeah, seconded with my own tracing as well.

@ammaraskar
Copy link
Member

Closing, here's the bug in dateutil's repo: dateutil/dateutil#197

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

2 participants