Skip to content

Commit 64a7f0f

Browse files
authored
Fix funnel trends backwards compatibility (#4978)
* Fix funnel trends backwards compatibility * Don't set funnel_viz_type outside of funnel insight filters * Reorder conditions for clarity and use null check
1 parent a1e2f14 commit 64a7f0f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

ee/clickhouse/views/insights.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ def calculate_funnel(self, request: Request) -> Dict[str, Any]:
7474
team = self.team
7575
filter = Filter(request=request, data={"insight": INSIGHT_FUNNELS})
7676

77-
# backwards compatibility - unsure of implications yet
78-
# but it's very confusing that funnel trends constant is same as the Trends display constant
79-
if not filter.funnel_viz_type and filter.display == TRENDS_LINEAR:
80-
filter.funnel_viz_type = FunnelVizType.TRENDS
81-
8277
if filter.funnel_viz_type == FunnelVizType.TRENDS:
8378
return {"result": ClickhouseFunnelTrends(team=team, filter=filter).run()}
8479
elif filter.funnel_order_type == FunnelOrderType.UNORDERED:

posthog/models/filters/mixins/funnel.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from typing import Optional
22

33
from posthog.constants import (
4+
DISPLAY,
45
FUNNEL_FROM_STEP,
56
FUNNEL_ORDER_TYPE,
67
FUNNEL_STEP,
78
FUNNEL_TO_STEP,
89
FUNNEL_VIZ_TYPE,
910
FUNNEL_WINDOW_DAYS,
11+
INSIGHT,
12+
INSIGHT_FUNNELS,
13+
TRENDS_LINEAR,
1014
FunnelOrderType,
1115
FunnelVizType,
1216
)
@@ -83,11 +87,22 @@ def funnel_order_type(self) -> Optional[FunnelOrderType]:
8387

8488
@cached_property
8589
def funnel_viz_type(self) -> Optional[FunnelVizType]:
86-
return self._data.get(FUNNEL_VIZ_TYPE)
90+
funnel_viz_type = self._data.get(FUNNEL_VIZ_TYPE)
91+
if (
92+
not funnel_viz_type is None
93+
and self._data.get(INSIGHT) == INSIGHT_FUNNELS
94+
and self._data.get(DISPLAY) == TRENDS_LINEAR
95+
):
96+
# Backwards compatibility
97+
# Before Filter.funnel_viz_type funnel trends were indicated by Filter.display being TRENDS_LINEAR
98+
return FunnelVizType.TRENDS
99+
return funnel_viz_type
87100

88101
@include_dict
89102
def funnel_type_to_dict(self):
90103
result = {}
91-
result.update({FUNNEL_ORDER_TYPE: self.funnel_order_type} if self.funnel_order_type else {})
92-
result.update({FUNNEL_VIZ_TYPE: self.funnel_viz_type} if self.funnel_viz_type else {})
104+
if self.funnel_order_type:
105+
result[FUNNEL_ORDER_TYPE] = self.funnel_order_type
106+
if self.funnel_viz_type:
107+
result[FUNNEL_VIZ_TYPE] = self.funnel_viz_type
93108
return result

0 commit comments

Comments
 (0)