Skip to content
Myr

Correctly encode aware, non-UTC datetime objects

Before adoption: this commit came in with the history the project adopted, so no landing records it.

http_date() requires timetuple in UTC, but JSONEncoder.default() was passing a local timetuple instead.

authored by Eugene M. Kim · committed by Eugene M. Kim · parent d75d83d · Browse files · 2 files+5 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+5 added−1 removed

  • other:+5 added−1 removed

2 files+5 added−1 removed

modified:flask/json/__init__.py+3 added-1 removed
1# -*- coding: utf-8 -*-2import io3import uuid4from datetime import date4from datetime import date, datetime5from flask.globals import current_app, request6from flask._compat import text_type, PY278from werkzeug.http import http_date
52 unmodified lines
61 else:62 return list(iterable)63 return JSONEncoder.default(self, o)64 """65 if isinstance(o, datetime):66 return http_date(o.utctimetuple())67 if isinstance(o, date):68 return http_date(o.timetuple())69 if isinstance(o, uuid.UUID):70 return str(o)
203 unmodified lines
modified:CHANGES+2 added
77 unmodified lines
78 the response to make testing JSON response much easier. (`#2358`_)79- Removed error handler caching because it caused unexpected results for some80 exception inheritance hierarchies. Register handlers explicitly for each81 exception if you don't want to traverse the MRO. (`#2362`_)82- Fix incorrect JSON encoding of aware, non-UTC datetimes. (`#2374`_)8384.. _#1489: https://github.com/pallets/flask/pull/148985.. _#1621: https://github.com/pallets/flask/pull/162186.. _#1898: https://github.com/pallets/flask/pull/1898
15 unmodified lines
102.. _#2352: https://github.com/pallets/flask/pull/2352103.. _#2354: https://github.com/pallets/flask/pull/2354104.. _#2358: https://github.com/pallets/flask/pull/2358105.. _#2362: https://github.com/pallets/flask/pull/2362106.. _#2374: https://github.com/pallets/flask/pull/2374107108Version 0.12.2109--------------110
617 unmodified lines