Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Discovered primarily because PyPy uses the Python version ofdatetime from the stdlib, anddjango.utils.dateparse.parse_datetime() supports wider range of values than the C version ofdatetime.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 (mostrecentcalllast):File"<python-input-9>",line1,in<module>datetime.datetime.fromisoformat("2012-04-23T10:20:30.400 ")~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/home/mgorny/git/cpython/Lib/_pydatetime.py",line1949,infromisoformatraiseValueError(f'Invalid isoformat string:{date_string!r}')fromNoneValueError:Invalidisoformatstring:'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