From 652b75d72f0cd34368e678c801aa7c98dc4f4c5e Mon Sep 17 00:00:00 2001 From: Robbie Date: Mon, 25 Mar 2024 21:14:51 +0000 Subject: [PATCH] feat(web-analytics): Support null as string in channel type (#21136) Support null as string in channel type --- posthog/hogql/database/schema/channel_type.py | 5 ++++- .../database/schema/test/test_channel_type.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/posthog/hogql/database/schema/channel_type.py b/posthog/hogql/database/schema/channel_type.py index 4954cc5be2b29..1552a0e6aa6d4 100644 --- a/posthog/hogql/database/schema/channel_type.py +++ b/posthog/hogql/database/schema/channel_type.py @@ -63,7 +63,10 @@ def create_channel_type_expr( gad_source: ast.Expr, ) -> ast.Expr: def wrap_with_null_if_empty(expr: ast.Expr) -> ast.Expr: - return ast.Call(name="nullIf", args=[expr, ast.Constant(value="")]) + return ast.Call( + name="nullIf", + args=[ast.Call(name="nullIf", args=[expr, ast.Constant(value="")]), ast.Constant(value="null")], + ) return parse_expr( """ diff --git a/posthog/hogql/database/schema/test/test_channel_type.py b/posthog/hogql/database/schema/test/test_channel_type.py index 10cd4ea4ae009..97dba3e13ba38 100644 --- a/posthog/hogql/database/schema/test/test_channel_type.py +++ b/posthog/hogql/database/schema/test/test_channel_type.py @@ -121,6 +121,21 @@ def test_direct_empty_string(self): ), ) + def test_direct_null_string(self): + self.assertEqual( + "Direct", + self._get_initial_channel_type( + { + "$initial_referring_domain": "$direct", + "$initial_utm_source": "null", + "$initial_utm_medium": "null", + "$initial_utm_campaign": "null", + "$initial_gclid": "null", + "$initial_gad_source": "null", + } + ), + ) + def test_cross_network(self): self.assertEqual( "Cross Network",