aio-libs / aio-libs/aiohttp

Naive datetime is interpreted as UTC when set last_modified

オープン
#5,304 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
16.5k
フォーク
2.4k
平均マージ
17時間 22分
マージ済み PR(30日)
212

説明

When set the `last_modified` property of `StreamResponse` the naive datetime object is interpreted as UTC. But naive datetime objects are usually in local timezone. For example `datetime.now()` returns naive datetime objects in local timezone. It provokes bugs in user code.

For example:
```
$ cat test_last_modified2.py
from aiohttp.web import StreamResponse
from datetime import datetime, timezone

resp = StreamResponse()
dt = datetime.now(timezone.utc)
dt2 = datetime.now()
resp.last_modified = dt
print(resp.last_modified)
print(repr(resp.last_modified))
print(resp.headers["Last-Modified"])
resp.last_modified = dt2
print(resp.last_modified)
print(repr(resp.last_modified))
print(resp.headers["Last-Modified"])
```
```
$ python test_last_modified2.py
2020-12-02 10:06:47+00:00
datetime.datetime(2020, 12, 2, 10, 6, 47, tzinfo=datetime.timezone.utc)
Wed, 02 Dec 2020 10:06:47 GMT
2020-12-02 12:06:47+00:00
datetime.datetime(2020, 12, 2, 12, 6, 47, tzinfo=datetime.timezone.utc)
Wed, 02 Dec 2020 12:06:47 GMT
```
It would be better either raise an error if naive datetime object is passed or interpret it as local time.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。