Closed
Description
Bug report
Bug description:
Discovered primarily because PyPy uses the Python version of datetime
from the stdlib, and django.utils.dateparse.parse_datetime()
supports wider range of values than the C version of datetime.datetime.fromisoformat()
, and falls back to their own parser.
>>> datetime.datetime.fromisoformat("2012-04-23T10:20:30.400")
datetime.datetime(2012, 4, 23, 10, 20, 30, 400000)
>>> datetime.datetime.fromisoformat("2012-04-23T10:20:30.400 ")
datetime.datetime(2012, 4, 23, 10, 20, 30, 40000)
>>> datetime.datetime.fromisoformat("2012-04-23T10:20:30.400 ")
datetime.datetime(2012, 4, 23, 10, 20, 30, 4000)
>>> datetime.datetime.fromisoformat("2012-04-23T10:20:30.400 ")
datetime.datetime(2012, 4, 23, 10, 20, 30, 400)
>>> datetime.datetime.fromisoformat("2012-04-23T10:20:30.400 ")
Traceback (most recent call last):
File "<python-input-9>", line 1, in <module>
datetime.datetime.fromisoformat("2012-04-23T10:20:30.400 ")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mgorny/git/cpython/Lib/_pydatetime.py", line 1949, in fromisoformat
raise ValueError(
f'Invalid isoformat string: {date_string!r}') from None
ValueError: Invalid isoformat string: '2012-04-23T10:20:30.400 '
>>> datetime.datetime.fromisoformat("2012-04-23T10:20:30.400 +02:30")
datetime.datetime(2012, 4, 23, 10, 20, 30, 40000, tzinfo=datetime.timezone(datetime.timedelta(seconds=9000)))
For comparison, the C extension rejects all variants containing spaces, causing Django to use its own parser.
PyPy bug report: pypy/pypy#5240
I'm going to try preparing a patch.
CPython versions tested on:
3.11, 3.13, CPython main branch
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done