Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(hogql): avoid DST errors in is_integer_timezone (#126899)

Phil Haacke78a1f2465f9
diff --git a/posthog/hogql/transforms/preaggregated_table_transformation.py b/posthog/hogql/transforms/preaggregated_table_transformation.py
index d935819225e6..f4ae754afa67 100644
--- a/posthog/hogql/transforms/preaggregated_table_transformation.py
+++ b/posthog/hogql/transforms/preaggregated_table_transformation.py
@@ -567,8 +567,9 @@ def is_integer_timezone(timezone: str) -> bool:
parsed = pytz.timezone(timezone)
except pytz.UnknownTimeZoneError:
return False
- now = datetime.now()
- offset = parsed.utcoffset(now)
+ # An aware datetime avoids pytz raising on a naive time in a DST transition hour.
+ offset = datetime.now(parsed).utcoffset()
+ assert offset is not None
return offset.total_seconds() % 3600 == 0
diff --git a/posthog/hogql/transforms/test/test_preaggregated_table_transformation.py b/posthog/hogql/transforms/test/test_preaggregated_table_transformation.py
index 2bd0baccc3d0..25ace5bfe53c 100644
--- a/posthog/hogql/transforms/test/test_preaggregated_table_transformation.py
+++ b/posthog/hogql/transforms/test/test_preaggregated_table_transformation.py
@@ -830,6 +830,23 @@ GROUP BY date
assert PREAGGREGATED_TABLE_NAME not in query
+class TestIsIntegerTimezone(unittest.TestCase):
+ @parameterized.expand(
+ [
+ ("new_york_ambiguous", "America/New_York", datetime(2026, 11, 1, 1, 30, tzinfo=UTC), True),
+ ("new_york_nonexistent", "America/New_York", datetime(2026, 3, 8, 2, 30, tzinfo=UTC), True),
+ ("london_ambiguous", "Europe/London", datetime(2026, 10, 25, 1, 30, tzinfo=UTC), True),
+ ("london_nonexistent", "Europe/London", datetime(2026, 3, 29, 1, 30, tzinfo=UTC), True),
+ ("sydney_ambiguous", "Australia/Sydney", datetime(2026, 4, 5, 2, 30, tzinfo=UTC), True),
+ ("sydney_nonexistent", "Australia/Sydney", datetime(2026, 10, 4, 2, 30, tzinfo=UTC), True),
+ ("adelaide_ambiguous", "Australia/Adelaide", datetime(2026, 4, 5, 2, 30, tzinfo=UTC), False),
+ ]
+ )
+ def test_integer_timezones_in_dst_transition_hour(self, _name, timezone, instant, expected):
+ with time_machine.travel(instant, tick=False):
+ assert is_integer_timezone(timezone) is expected
+
+
@snapshot_clickhouse_queries
@override_settings(CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA=False)
class TestPreaggregatedTableTransformationIntegration(APIBaseTest, ClickhouseTestMixin):