From e8c683d5af0cf71b245fd5848723100cae72953d Mon Sep 17 00:00:00 2001 From: kwy404 Date: Thu, 24 Sep 2026 20:42:37 -0300 Subject: [PATCH 1/3] fix(oauth): treat naive datetime values as UTC when converting to timestamps --- slack_sdk/oauth/installation_store/internals.py | 5 ++++- tests/slack_sdk/oauth/installation_store/test_internals.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/slack_sdk/oauth/installation_store/internals.py b/slack_sdk/oauth/installation_store/internals.py index 52eeeb98b..aa344d664 100644 --- a/slack_sdk/oauth/installation_store/internals.py +++ b/slack_sdk/oauth/installation_store/internals.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timezone from typing import Type, TypeVar, Union @@ -28,6 +28,9 @@ def _timestamp_to_type(ts: Union[TimestampType, datetime, str], target_type: Typ # see https://github.com/google/pytype/issues/1012 elif isinstance(ts, datetime): + if ts.tzinfo is None: + # naive datetime values (e.g., loaded from a database) are stored in UTC + ts = ts.replace(tzinfo=timezone.utc) result = target_type(ts.timestamp()) elif isinstance(ts, str): try: diff --git a/tests/slack_sdk/oauth/installation_store/test_internals.py b/tests/slack_sdk/oauth/installation_store/test_internals.py index 74cb935fc..8f9759088 100644 --- a/tests/slack_sdk/oauth/installation_store/test_internals.py +++ b/tests/slack_sdk/oauth/installation_store/test_internals.py @@ -25,6 +25,7 @@ def test_iso_format(self): [ (1701209097, int, 1701209097), (datetime(2023, 11, 28, 22, 9, 7, tzinfo=timezone.utc), int, 1701209347), + (datetime(2023, 11, 28, 22, 9, 7), int, 1701209347), ("1701209605", int, 1701209605), ("2023-11-28 22:11:19", int, 1701209479), (1701209998.3429494, float, 1701209998.3429494), From dac8de3690fe8324bcf4ff7df992266b53d90ee2 Mon Sep 17 00:00:00 2001 From: kwy404 Date: Thu, 24 Sep 2026 21:46:45 -0300 Subject: [PATCH 2/3] Trigger CLA check From 1c008a40de5f8fdce0624ee52a15f5221ca3830b Mon Sep 17 00:00:00 2001 From: kwy404 Date: Fri, 25 Sep 2026 19:01:30 -0300 Subject: [PATCH 3/3] test: force a non-UTC timezone for the naive datetime case --- .../oauth/installation_store/test_internals.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/slack_sdk/oauth/installation_store/test_internals.py b/tests/slack_sdk/oauth/installation_store/test_internals.py index 8f9759088..a34dc617c 100644 --- a/tests/slack_sdk/oauth/installation_store/test_internals.py +++ b/tests/slack_sdk/oauth/installation_store/test_internals.py @@ -1,6 +1,9 @@ +import os import sys +import time import unittest from datetime import datetime, timezone +from unittest import mock import pytest @@ -25,7 +28,6 @@ def test_iso_format(self): [ (1701209097, int, 1701209097), (datetime(2023, 11, 28, 22, 9, 7, tzinfo=timezone.utc), int, 1701209347), - (datetime(2023, 11, 28, 22, 9, 7), int, 1701209347), ("1701209605", int, 1701209605), ("2023-11-28 22:11:19", int, 1701209479), (1701209998.3429494, float, 1701209998.3429494), @@ -39,6 +41,16 @@ def test_timestamp_to_type(ts, target_type, expected_result): assert result == expected_result +@pytest.mark.skipif(not hasattr(time, "tzset"), reason="time.tzset is not available on this platform") +def test_timestamp_to_type_naive_datetime_is_utc(): + try: + with mock.patch.dict(os.environ, {"TZ": "America/New_York"}): + time.tzset() + assert _timestamp_to_type(datetime(2023, 11, 28, 22, 9, 7), int) == 1701209347 + finally: + time.tzset() + + def test_timestamp_to_type_invalid_str(): match = "Invalid isoformat string" with pytest.raises(ValueError, match=match):