From b132309447b6398680cd0bb8997b3ca072900f51 Mon Sep 17 00:00:00 2001 From: Sandy Spicer Date: Thu, 12 Dec 2024 02:25:47 +0000 Subject: [PATCH 1/2] fix --- posthog/hogql_queries/insights/funnels/base.py | 4 +++- .../insights/funnels/test/test_funnel.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/posthog/hogql_queries/insights/funnels/base.py b/posthog/hogql_queries/insights/funnels/base.py index 98d0cedea69b9..8d11a84473f48 100644 --- a/posthog/hogql_queries/insights/funnels/base.py +++ b/posthog/hogql_queries/insights/funnels/base.py @@ -726,7 +726,9 @@ def _build_step_query( first_time_filter = parse_expr("e.uuid IN {subquery}", placeholders={"subquery": subquery}) return ast.And(exprs=[*filters, first_time_filter]) elif entity.math == FunnelMathType.FIRST_TIME_FOR_USER_WITH_FILTERS: - subquery = FirstTimeForUserAggregationQuery(self.context, ast.Constant(value=1), filter_expr).to_query() + subquery = FirstTimeForUserAggregationQuery( + self.context, ast.Constant(value=1), ast.And(exprs=filters) + ).to_query() first_time_filter = parse_expr("e.uuid IN {subquery}", placeholders={"subquery": subquery}) return ast.And(exprs=[*filters, first_time_filter]) elif len(filters) > 1: diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel.py b/posthog/hogql_queries/insights/funnels/test/test_funnel.py index b90a3d9eedd62..069cd31781ec7 100644 --- a/posthog/hogql_queries/insights/funnels/test/test_funnel.py +++ b/posthog/hogql_queries/insights/funnels/test/test_funnel.py @@ -4429,6 +4429,19 @@ def test_first_time_for_user_funnel_person_properties(self): # classic and udf funnels handle no events differently assert len(results) == 0 or results[0]["count"] == 0 + _create_event( + team=self.team, + event="event2", + distinct_id="user_1", + timestamp="2024-03-19T13:00:00Z", + properties={"property": "woah"}, + ) + query.series[0].math = FunnelMathType.FIRST_TIME_FOR_USER_WITH_FILTERS + query.dateRange.date_from = "2024-03-19" + results = FunnelsQueryRunner(query=query, team=self.team).calculate().results + self.assertEqual(results[0]["count"], 1) + self.assertEqual(results[1]["count"], 1) + def test_funnel_personless_events_are_supported(self): user_id = uuid.uuid4() _create_event( From 162a5a74ee5384792403e641599851c45a59f51e Mon Sep 17 00:00:00 2001 From: Sandy Spicer Date: Thu, 12 Dec 2024 02:47:06 +0000 Subject: [PATCH 2/2] annoying assert for type safety --- posthog/hogql_queries/insights/funnels/test/test_funnel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel.py b/posthog/hogql_queries/insights/funnels/test/test_funnel.py index 069cd31781ec7..2c762f279331b 100644 --- a/posthog/hogql_queries/insights/funnels/test/test_funnel.py +++ b/posthog/hogql_queries/insights/funnels/test/test_funnel.py @@ -4437,6 +4437,7 @@ def test_first_time_for_user_funnel_person_properties(self): properties={"property": "woah"}, ) query.series[0].math = FunnelMathType.FIRST_TIME_FOR_USER_WITH_FILTERS + assert query.dateRange is not None query.dateRange.date_from = "2024-03-19" results = FunnelsQueryRunner(query=query, team=self.team).calculate().results self.assertEqual(results[0]["count"], 1)