[New-bugs-announce] [issue46447] datetime.isoformat() documentation does not point to the risk of using it with naive datetime objects
Jean Carlo Machado
report at bugs.python.org
Thu Jan 20 16:16:16 EST 2022
New submission from Jean Carlo Machado <jean.machado at getyourguide.com>:
datetime.utcnow() already present a warning box describing the risk of using it without specifying timezone information. However, one might still have the same problem and never encounter this warning information by doing datetime.now().isoformat(). Or just by not reading the docs of datetime.utcnow, just the datetime.isoformat docs.
By adding a similar warning to the datetime.isoformat() we could make the risk clearer and reduce the likelihood of errors. Is when calling isoformat() where people get confident to be producing ISO's.
I just recently had an incident in my company where we produced naive datetimes using datetime.now() and serialized them using isoformat() while expecting them to be a transferrable ISO format. Nevertheless, the other system read the dates without Z in the end and interpreted it as local time.
If you agree that this suggestion could be a good improvement to the docs, I can send a patch in the next 2 weeks.
assignee: docs at python
nosy: docs at python, jeanCarloMachado
title: datetime.isoformat() documentation does not point to the risk of using it with naive datetime objects
versions: Python 3.11
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce