From 2e8a4a303423348fd223dff2f66ed7f9b9a38f28 Mon Sep 17 00:00:00 2001 From: Rafa Audibert Date: Wed, 27 Nov 2024 10:47:31 +0000 Subject: [PATCH] bug: fix bug with etc/unknown timezone --- posthog/hogql_queries/web_analytics/stats_table.py | 2 +- .../web_analytics/test/test_web_stats_table.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/posthog/hogql_queries/web_analytics/stats_table.py b/posthog/hogql_queries/web_analytics/stats_table.py index fef2c71af7fdb..a693fd59f48a7 100644 --- a/posthog/hogql_queries/web_analytics/stats_table.py +++ b/posthog/hogql_queries/web_analytics/stats_table.py @@ -508,7 +508,7 @@ def _counts_breakdown_value(self): # Get the difference between the UNIX timestamp at UTC and the UNIX timestamp at the event's timezone # Value is in milliseconds, turn it to hours, works even for fractional timezone offsets (I'm looking at you, Australia) return parse_expr( - "if(or(isNull(properties.$timezone), empty(properties.$timezone)), NULL, (toUnixTimestamp64Milli(parseDateTimeBestEffort(assumeNotNull(toString(timestamp, properties.$timezone)))) - toUnixTimestamp64Milli(timestamp)) / 3600000)" + "if(or(isNull(properties.$timezone), empty(properties.$timezone), properties.$timezone == 'Etc/Unknown'), NULL, (toUnixTimestamp64Milli(parseDateTimeBestEffort(assumeNotNull(toString(timestamp, properties.$timezone)))) - toUnixTimestamp64Milli(timestamp)) / 3600000)" ) case _: raise NotImplementedError("Breakdown not implemented") diff --git a/posthog/hogql_queries/web_analytics/test/test_web_stats_table.py b/posthog/hogql_queries/web_analytics/test/test_web_stats_table.py index 616d406978ca1..493ea6dc7d567 100644 --- a/posthog/hogql_queries/web_analytics/test/test_web_stats_table.py +++ b/posthog/hogql_queries/web_analytics/test/test_web_stats_table.py @@ -1137,6 +1137,15 @@ def test_timezone_filter_with_empty_timezone(self): properties={"$session_id": sid, "$pathname": f"/path1", "$timezone": ""}, ) + # Key exists, it's set to the invalid 'Etc/Unknown' timezone + _create_event( + team=self.team, + event="$pageview", + distinct_id=did, + timestamp=f"2019-02-17 00:00:00", + properties={"$session_id": sid, "$pathname": f"/path1", "$timezone": "Etc/Unknown"}, + ) + results = self._run_web_stats_table_query( "all", None,