Skip to content

Commit e8c683d

Browse files
committed
fix(oauth): treat naive datetime values as UTC when converting to timestamps
1 parent 77d0a1a commit e8c683d

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎slack_sdk/oauth/installation_store/internals.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime
1+
from datetime import datetime, timezone
22
from typing import Type, TypeVar, Union
33

44

@@ -28,6 +28,9 @@ def _timestamp_to_type(ts: Union[TimestampType, datetime, str], target_type: Typ
2828
# see https://github.com/google/pytype/issues/1012
2929

3030
elif isinstance(ts, datetime):
31+
if ts.tzinfo is None:
32+
# naive datetime values (e.g., loaded from a database) are stored in UTC
33+
ts = ts.replace(tzinfo=timezone.utc)
3134
result = target_type(ts.timestamp())
3235
elif isinstance(ts, str):
3336
try:

‎tests/slack_sdk/oauth/installation_store/test_internals.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_iso_format(self):
2525
[
2626
(1701209097, int, 1701209097),
2727
(datetime(2023, 11, 28, 22, 9, 7, tzinfo=timezone.utc), int, 1701209347),
28+
(datetime(2023, 11, 28, 22, 9, 7), int, 1701209347),
2829
("1701209605", int, 1701209605),
2930
("2023-11-28 22:11:19", int, 1701209479),
3031
(1701209998.3429494, float, 1701209998.3429494),

0 commit comments

Comments
 (0)