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(insights): enable daysOfWeek for all funnel viz types, drop it from lifecycle (#76551)

Sam Penningtona1c0d0628950
diff --git a/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx b/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx
index 1f613ace5ac7..d609b83a9a5b 100644
--- a/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx
+++ b/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx
@@ -37,16 +37,16 @@ export function InsightDateFilter({ disabled }: InsightDateFilterProps): JSX.Ele
const smoothingActive = isTrends && (trendsFilter?.smoothingIntervals ?? 1) > 1
const showDaysOfWeekExclusions = supportsDaysOfWeek && !smoothingActive
- // Enabling smoothing hides the control, so clear daysOfWeek on that transition (never on
- // mount): the backend rejects the combination and there'd be no UI left to remove it
+ // Hiding the control for any reason (smoothing turned on, or the insight changed to an
+ // unsupported kind) must clear daysOfWeek too, or it lingers with no UI left to remove it
const prevShowDaysOfWeekExclusions = useRef(showDaysOfWeekExclusions)
useEffect(() => {
const wasShown = prevShowDaysOfWeekExclusions.current
prevShowDaysOfWeekExclusions.current = showDaysOfWeekExclusions
- if (wasShown && !showDaysOfWeekExclusions && smoothingActive && dateRange?.daysOfWeek?.length) {
+ if (wasShown && !showDaysOfWeekExclusions && dateRange?.daysOfWeek?.length) {
updateQuerySource(computeDaysOfWeekUpdate([], dateRange))
}
- }, [showDaysOfWeekExclusions, smoothingActive, dateRange, updateQuerySource])
+ }, [showDaysOfWeekExclusions, dateRange, updateQuerySource])
const exclusions: DateFilterExclusions = {
days: showDaysOfWeekExclusions ? excludedDaysOfWeek.map(String) : [],
diff --git a/frontend/src/scenes/insights/filters/InsightDateFilter/InsightQuillDateFilter.test.tsx b/frontend/src/scenes/insights/filters/InsightDateFilter/InsightQuillDateFilter.test.tsx
index bd43056465a7..1c296c08442b 100644
--- a/frontend/src/scenes/insights/filters/InsightDateFilter/InsightQuillDateFilter.test.tsx
+++ b/frontend/src/scenes/insights/filters/InsightDateFilter/InsightQuillDateFilter.test.tsx
@@ -8,7 +8,7 @@ import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { useMocks } from '~/mocks/jest'
-import { FunnelsQuery, NodeKind, TrendsQuery } from '~/queries/schema/schema-general'
+import { LifecycleQuery, NodeKind, TrendsQuery } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
import { InsightShortId } from '~/types'
@@ -26,9 +26,9 @@ function makeTrendsQuery(daysOfWeek: IsoDayOfWeek[] | null = null): TrendsQuery
}
}
-function makeFunnelsStepsQuery(daysOfWeek: IsoDayOfWeek[] | null = null): FunnelsQuery {
+function makeLifecycleQuery(daysOfWeek: IsoDayOfWeek[] | null = null): LifecycleQuery {
return {
- kind: NodeKind.FunnelsQuery,
+ kind: NodeKind.LifecycleQuery,
series: [{ kind: NodeKind.EventsNode, name: '$pageview', event: '$pageview' }],
dateRange: { date_from: '-7d', daysOfWeek },
}
@@ -56,7 +56,7 @@ describe('InsightQuillDateFilter', () => {
cleanup()
})
- function setupAndRender(query: TrendsQuery | FunnelsQuery): void {
+ function setupAndRender(query: TrendsQuery | LifecycleQuery): void {
vizDataLogic.actions.updateQuerySource(query)
render(
@@ -72,7 +72,7 @@ describe('InsightQuillDateFilter', () => {
setupAndRender(makeTrendsQuery([1, 2, 3, 4, 5]))
expect(vizDataLogic.values.dateRange?.daysOfWeek).toEqual([1, 2, 3, 4, 5])
- vizDataLogic.actions.updateQuerySource(makeFunnelsStepsQuery([1, 2, 3, 4, 5]))
+ vizDataLogic.actions.updateQuerySource(makeLifecycleQuery([1, 2, 3, 4, 5]))
await waitFor(() => {
expect(vizDataLogic.values.dateRange?.daysOfWeek ?? null).toBeNull()
diff --git a/frontend/src/scenes/insights/filters/InsightDateFilter/daysOfWeekFilterUtils.test.ts b/frontend/src/scenes/insights/filters/InsightDateFilter/daysOfWeekFilterUtils.test.ts
index c4bb13f0db43..cce8441c786b 100644
--- a/frontend/src/scenes/insights/filters/InsightDateFilter/daysOfWeekFilterUtils.test.ts
+++ b/frontend/src/scenes/insights/filters/InsightDateFilter/daysOfWeekFilterUtils.test.ts
@@ -69,10 +69,10 @@ describe('daysOfWeekFilterUtils', () => {
[undefined, false],
[{ kind: NodeKind.TrendsQuery }, true],
[{ kind: NodeKind.StickinessQuery }, true],
- [{ kind: NodeKind.LifecycleQuery }, true],
- [{ kind: NodeKind.FunnelsQuery }, false],
- [{ kind: NodeKind.FunnelsQuery, funnelsFilter: { funnelVizType: FunnelVizType.Steps } }, false],
- [{ kind: NodeKind.FunnelsQuery, funnelsFilter: { funnelVizType: FunnelVizType.TimeToConvert } }, false],
+ [{ kind: NodeKind.LifecycleQuery }, false],
+ [{ kind: NodeKind.FunnelsQuery }, true],
+ [{ kind: NodeKind.FunnelsQuery, funnelsFilter: { funnelVizType: FunnelVizType.Steps } }, true],
+ [{ kind: NodeKind.FunnelsQuery, funnelsFilter: { funnelVizType: FunnelVizType.TimeToConvert } }, true],
[{ kind: NodeKind.FunnelsQuery, funnelsFilter: { funnelVizType: FunnelVizType.Trends } }, true],
[{ kind: NodeKind.RetentionQuery }, false],
[{ kind: NodeKind.PathsQuery }, false],
diff --git a/frontend/src/scenes/insights/filters/InsightDateFilter/daysOfWeekFilterUtils.ts b/frontend/src/scenes/insights/filters/InsightDateFilter/daysOfWeekFilterUtils.ts
index 8775ea731da9..9d1a4d8eedc0 100644
--- a/frontend/src/scenes/insights/filters/InsightDateFilter/daysOfWeekFilterUtils.ts
+++ b/frontend/src/scenes/insights/filters/InsightDateFilter/daysOfWeekFilterUtils.ts
@@ -1,16 +1,13 @@
import { DateRange } from '~/queries/schema/schema-general'
-import { isFunnelsQuery, isLifecycleQuery, isStickinessQuery, isTrendsQuery } from '~/queries/utils'
-import { FunnelVizType } from '~/types'
+import { isFunnelsQuery, isStickinessQuery, isTrendsQuery } from '~/queries/utils'
export type IsoDayOfWeek = NonNullable<DateRange['daysOfWeek']>[number]
-/** Mirrors backend support: trends, stickiness, lifecycle, and funnels in the trends viz only
- * (dropping mid-sequence events from a step funnel has ambiguous semantics). */
+/** Mirrors backend support: trends, stickiness, and funnels. Lifecycle is excluded because its
+ * statuses are defined by interval adjacency, which a sparse day axis breaks (weekend-only users
+ * get misclassified as resurrecting, dormant lands on excluded days). */
export function querySupportsDaysOfWeek(querySource: Record<string, any> | null | undefined): boolean {
- if (isTrendsQuery(querySource) || isStickinessQuery(querySource) || isLifecycleQuery(querySource)) {
- return true
- }
- return isFunnelsQuery(querySource) && querySource.funnelsFilter?.funnelVizType === FunnelVizType.Trends
+ return isTrendsQuery(querySource) || isStickinessQuery(querySource) || isFunnelsQuery(querySource)
}
const DAYS_IN_WEEK = 7
diff --git a/posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py b/posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py
index 448e352a28ac..9ba6d3f517fe 100644
--- a/posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py
+++ b/posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py
@@ -323,6 +323,9 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationRespons
return events, skewed_totals, hogql, response
def _date_range(self) -> QueryDateRange:
+ # daysOfWeek scopes funnel step attribution, not the correlation event scan: actors are
+ # already day-filtered, and "what else did they do while converting" reads over their whole
+ # window. Deliberate — see test_days_of_week_does_not_filter_correlation_events.
return QueryDateRange(
date_range=self.context.query.dateRange,
team=self.context.team,
diff --git a/posthog/hogql_queries/insights/funnels/funnel_event_query.py b/posthog/hogql_queries/insights/funnels/funnel_event_query.py
index d2636b5b8f55..a69d80e9685e 100644
--- a/posthog/hogql_queries/insights/funnels/funnel_event_query.py
+++ b/posthog/hogql_queries/insights/funnels/funnel_event_query.py
@@ -13,7 +13,6 @@ from posthog.schema import (
FunnelExclusionEventsNode,
FunnelMathType,
FunnelsDataWarehouseNode,
- FunnelVizType,
GroupNode,
StepOrderValue,
)
@@ -650,11 +649,11 @@ class FunnelEventQuery(DataWarehouseSchemaMixin):
)
def _day_of_week_filter_expr(self, timestamp_field: ast.Expr) -> ast.Expr | None:
- # daysOfWeek only applies to the funnel trends visualization. Regular funnels and
- # time-to-convert are untouched: dropping mid-sequence events has ambiguous semantics
- # there, which needs a product decision first.
- if self.context.funnelsFilter.funnelVizType != FunnelVizType.TRENDS:
- return None
+ # Applies to every funnel viz type: events on excluded days don't exist for the funnel,
+ # so a step performed on an excluded day doesn't count towards the sequence, while the
+ # conversion window itself still spans excluded days. This holds regardless of
+ # skip_entity_filter, so strict order and exclusion steps can't see excluded-day events
+ # either — see test_days_of_week_hides_intervening_events_from_strict_order.
return self._date_range().day_of_week_filter_expr(timestamp_field)
def _entity_expr(self, skip_entity_filter: bool) -> ast.Expr | None:
diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.py b/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.py
index 34a39de15955..bcf71222d50d 100644
--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.py
+++ b/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.py
@@ -162,6 +162,50 @@ class TestClickhouseFunnelCorrelation(ClickhouseTestMixin, APIBaseTest):
self.assertEqual(events["positively_related"]["success_count"], 5)
self.assertEqual(events["positively_related"]["correlation_type"], "success")
+ def test_days_of_week_does_not_filter_correlation_events(self):
+ # daysOfWeek scopes funnel step attribution, not the correlation event scan. Actors are
+ # already day-filtered, so correlation answers "what else did these people do while
+ # converting" over their whole window — a Saturday event still counts as a correlate.
+ # 2020-01-10 is a Friday, 2020-01-11 a Saturday, 2020-01-13 a Monday.
+ query = FunnelsQuery(
+ series=[EventsNode(event="user signed up"), EventsNode(event="paid")],
+ dateRange=DateRange(date_from="2020-01-06", date_to="2020-01-20", daysOfWeek=[1, 2, 3, 4, 5]),
+ )
+
+ # Converters: both steps on included weekdays, spanning a weekend, plus a Saturday event.
+ for i in range(5):
+ _create_person(distinct_ids=[f"converter_{i}"], team_id=self.team.pk)
+ _create_event(
+ team=self.team,
+ event="user signed up",
+ distinct_id=f"converter_{i}",
+ timestamp="2020-01-10T14:00:00Z",
+ )
+ _create_event(
+ team=self.team,
+ event="weekend_thing",
+ distinct_id=f"converter_{i}",
+ timestamp="2020-01-11T14:00:00Z",
+ )
+ _create_event(team=self.team, event="paid", distinct_id=f"converter_{i}", timestamp="2020-01-13T14:00:00Z")
+
+ # Non-converters, so failure_total is non-zero and odds ratios are computable.
+ for i in range(5):
+ _create_person(distinct_ids=[f"dropper_{i}"], team_id=self.team.pk)
+ _create_event(
+ team=self.team,
+ event="user signed up",
+ distinct_id=f"dropper_{i}",
+ timestamp="2020-01-10T14:00:00Z",
+ )
+
+ flush_persons_and_events()
+
+ result, _ = self._get_events_for_query(query)
+ events = {item["event"]: item for item in result}
+ self.assertIn("weekend_thing", events)
+ self.assertEqual(events["weekend_thing"]["success_count"], 5)
+
def test_funnel_correlation_hogql_aggregation_rejects_injection(self):
# funnelAggregateByHogQL is user-controlled — a value that isn't a single
# bounded expression (e.g. an attempt to inject an extra JOIN) must be
diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_strict.py b/posthog/hogql_queries/insights/funnels/test/test_funnel_strict.py
index 716e59f0783c..21eb9f6bee49 100644
--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_strict.py
+++ b/posthog/hogql_queries/insights/funnels/test/test_funnel_strict.py
@@ -188,6 +188,37 @@ class TestFunnelStrictSteps(ClickhouseTestMixin, APIBaseTest):
)
return [actor[0] for actor in actors]
+ def _run_days_of_week_strict_funnel(self, days_of_week):
+ query = FunnelsQuery(
+ series=[EventsNode(event="step one"), EventsNode(event="step two")],
+ dateRange=DateRange(date_from="2020-01-06", date_to="2020-01-20", daysOfWeek=days_of_week),
+ funnelsFilter=FunnelsFilter(funnelOrderType=FunnelOrderType.STRICT, funnelWindowInterval=14),
+ )
+ return FunnelsQueryRunner(query=query, team=self.team).calculate().results
+
+ def test_days_of_week_hides_intervening_events_from_strict_order(self):
+ # Strict order inspects every event, not just funnel steps, so it can spot one breaking the
+ # sequence — but daysOfWeek filters that stream too. An interrupt on an excluded day is
+ # invisible and no longer breaks strictness, so excluding days can report *more*
+ # conversions than not filtering at all. Surprising, deliberate, pinned here.
+ # 2020-01-10 is a Friday, 2020-01-11 a Saturday, 2020-01-13 a Monday.
+ journeys_for(
+ {
+ "user_interrupted_on_saturday": [
+ {"event": "step one", "timestamp": datetime(2020, 1, 10, 12)},
+ {"event": "interrupt", "timestamp": datetime(2020, 1, 11, 12)},
+ {"event": "step two", "timestamp": datetime(2020, 1, 13, 12)},
+ ],
+ },
+ self.team,
+ )
+
+ weekdays_only = self._run_days_of_week_strict_funnel([1, 2, 3, 4, 5])
+ unfiltered = self._run_days_of_week_strict_funnel(None)
+
+ self.assertEqual(weekdays_only[1]["count"], 1)
+ self.assertEqual(unfiltered[1]["count"], 0)
+
def test_basic_strict_funnel(self):
query = FunnelsQuery(
series=[
diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_trends.py b/posthog/hogql_queries/insights/funnels/test/test_funnel_trends.py
index 247d1af333d0..df40662299a7 100644
--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_trends.py
+++ b/posthog/hogql_queries/insights/funnels/test/test_funnel_trends.py
@@ -3572,11 +3572,20 @@ class TestFunnelTrendsDaysOfWeekUDF(ClickhouseTestMixin, APIBaseTest):
self.assertEqual(len(converted), 1)
self.assertEqual(len(dropped_off), 1)
- def test_days_of_week_does_not_affect_steps_viz(self):
- # A regular (steps) funnel must ignore daysOfWeek until dropping mid-sequence
- # events gets defined semantics there
+ def test_days_of_week_filters_steps_viz(self):
+ # Events on excluded days don't exist for the funnel: user_saturday never enters,
+ # and user_cross's Tuesday step two doesn't count even though the conversion
+ # window spans it
journeys_for(
{
+ "user_monday": [
+ {"event": "step one", "timestamp": datetime(2021, 6, 7, 10)},
+ {"event": "step two", "timestamp": datetime(2021, 6, 7, 11)},
+ ],
+ "user_cross": [
+ {"event": "step one", "timestamp": datetime(2021, 6, 7, 12)},
+ {"event": "step two", "timestamp": datetime(2021, 6, 8, 12)},
+ ],
"user_saturday": [
{"event": "step one", "timestamp": datetime(2021, 6, 12, 10)},
{"event": "step two", "timestamp": datetime(2021, 6, 12, 11)},
@@ -3595,9 +3604,47 @@ class TestFunnelTrendsDaysOfWeekUDF(ClickhouseTestMixin, APIBaseTest):
)
results = FunnelsQueryRunner(query=query, team=self.team).calculate().results
- self.assertEqual(results[0]["count"], 1)
+ self.assertEqual(results[0]["count"], 2)
self.assertEqual(results[1]["count"], 1)
+ def test_days_of_week_filters_time_to_convert_viz(self):
+ # Only user_monday's conversion survives a Mondays-only filter; user_saturday's
+ # entrance and conversion are on an excluded day. user_saturday converts in 5 hours
+ # (vs. user_monday's 1 hour) so an unfiltered run would report a different average.
+ journeys_for(
+ {
+ "user_monday": [
+ {"event": "step one", "timestamp": datetime(2021, 6, 7, 10)},
+ {"event": "step two", "timestamp": datetime(2021, 6, 7, 11)},
+ ],
+ "user_saturday": [
+ {"event": "step one", "timestamp": datetime(2021, 6, 12, 10)},
+ {"event": "step two", "timestamp": datetime(2021, 6, 12, 15)},
+ ],
+ },
+ self.team,
+ )
+
+ query = FunnelsQuery(
+ dateRange=DateRange(
+ date_from="2021-06-07 00:00:00",
+ date_to="2021-06-13 23:59:59",
+ daysOfWeek=[1],
+ ),
+ series=[EventsNode(event="step one"), EventsNode(event="step two")],
+ funnelsFilter=FunnelsFilter(
+ funnelVizType=FunnelVizType.TIME_TO_CONVERT,
+ funnelFromStep=0,
+ funnelToStep=1,
+ funnelWindowInterval=7,
+ funnelWindowIntervalUnit=FunnelConversionWindowTimeUnit.DAY,
+ ),
+ )
+ results = FunnelsQueryRunner(query=query, team=self.team).calculate().results
+
+ # user_saturday is filtered out; only user_monday's one-hour conversion survives
+ self.assertEqual(results.average_conversion_time, 3600)
+
@override_settings(IN_UNIT_TESTING=True)
class TestFunnelTrendsCompareUDF(ClickhouseTestMixin, APIBaseTest):
diff --git a/posthog/hogql_queries/insights/lifecycle/lifecycle_query_runner.py b/posthog/hogql_queries/insights/lifecycle/lifecycle_query_runner.py
index 06c8fbd51139..1ec5f8b9a0f9 100644
--- a/posthog/hogql_queries/insights/lifecycle/lifecycle_query_runner.py
+++ b/posthog/hogql_queries/insights/lifecycle/lifecycle_query_runner.py
@@ -364,9 +364,9 @@ class LifecycleQueryRunner(AnalyticsQueryRunner[LifecycleQueryResponse]):
timings=self.timings,
)
)
- day_of_week_filter = self.query_date_range.day_of_week_filter_expr(self.timestamp_field)
- if day_of_week_filter is not None:
- event_filters.append(day_of_week_filter)
+ # dateRange.daysOfWeek is deliberately ignored: lifecycle statuses are defined by
+ # interval adjacency, which a sparse day axis breaks (weekend-only users would be
+ # misclassified as resurrecting, and dormant would land on excluded days).
with self.timings.measure("properties"):
if self.query.properties is not None and self.query.properties != []:
event_filters.append(property_to_expr(self.query.properties, self.team))
diff --git a/posthog/hogql_queries/insights/lifecycle/test/test_lifecycle_query_runner.py b/posthog/hogql_queries/insights/lifecycle/test/test_lifecycle_query_runner.py
index 302c6a87972d..b99b5763f909 100644
--- a/posthog/hogql_queries/insights/lifecycle/test/test_lifecycle_query_runner.py
+++ b/posthog/hogql_queries/insights/lifecycle/test/test_lifecycle_query_runner.py
@@ -810,97 +810,24 @@ class TestLifecycleQueryRunner(ClickhouseTestMixin, APIBaseTest):
def _run_lifecycle_query(self, date_from, date_to, interval, days_of_week=None):
return self._create_query_runner(date_from, date_to, interval, days_of_week).calculate()
- @parameterized.expand(
- [
- (
- "mondays_only",
- [1],
- [
- # dormant lands the day after last selected-day activity, which can be an
- # excluded day (Tue Jan 14) — buckets are deliberately kept so it stays visible
- {"status": "dormant", "data": [0, -1, 0, 0, 0, 0, 0]},
- {"status": "new", "data": [1, 0, 0, 0, 0, 0, 0]},
- {"status": "resurrecting", "data": [0, 0, 0, 0, 0, 0, 0]},
- {"status": "returning", "data": [0, 0, 0, 0, 0, 0, 0]},
- ],
- ),
- (
- "empty_means_unfiltered",
- [],
- [
- {"status": "dormant", "data": [0, -1, 0, -1, 0, 0, 0]},
- {"status": "new", "data": [1, 0, 0, 0, 0, 0, 0]},
- {"status": "resurrecting", "data": [0, 0, 1, 0, 0, 0, 0]},
- {"status": "returning", "data": [0, 0, 0, 0, 0, 0, 0]},
- ],
- ),
- ]
- )
- def test_days_of_week_filters_lifecycle_statuses(self, _name, days_of_week, expected):
+ def test_days_of_week_is_ignored(self):
+ # Lifecycle statuses are defined by interval adjacency, which a sparse day axis breaks,
+ # so a lingering daysOfWeek (e.g. saved before support was pulled) must be inert
# 2020-01-13 is a Monday; p1 is active Mon and Wed
self._create_events(data=[("p1", ["2020-01-13T12:00:00Z", "2020-01-15T12:00:00Z"])])
flush_persons_and_events()
- response = self._run_lifecycle_query("2020-01-13", "2020-01-19", IntervalType.DAY, days_of_week)
-
- # every day bucket stays in the response, including excluded days
- assert response.results[0]["days"] == [
- "2020-01-13",
- "2020-01-14",
- "2020-01-15",
- "2020-01-16",
- "2020-01-17",
- "2020-01-18",
- "2020-01-19",
- ]
- assertLifecycleResults(response.results, expected)
+ filtered = self._run_lifecycle_query("2020-01-13", "2020-01-19", IntervalType.DAY, days_of_week=[1])
+ unfiltered = self._run_lifecycle_query("2020-01-13", "2020-01-19", IntervalType.DAY)
- @parameterized.expand(
- [
- ("monday_filter_includes_it", [1], 1),
- ("sunday_filter_excludes_it", [7], 0),
+ expected = [
+ {"status": "dormant", "data": [0, -1, 0, -1, 0, 0, 0]},
+ {"status": "new", "data": [1, 0, 0, 0, 0, 0, 0]},
+ {"status": "resurrecting", "data": [0, 0, 1, 0, 0, 0, 0]},
+ {"status": "returning", "data": [0, 0, 0, 0, 0, 0, 0]},
]
- )
- def test_days_of_week_uses_project_timezone(self, _name, days_of_week, expected_new_count):
- self.team.timezone = "Asia/Tokyo"
- self.team.save()
- # 20:00 UTC Sunday = 05:00 Monday in Asia/Tokyo
- self._create_events(data=[("p1", ["2020-01-12T20:00:00Z"])])
- flush_persons_and_events()
-
- response = self._run_lifecycle_query("2020-01-13", "2020-01-19", IntervalType.DAY, days_of_week)
-
- new_series = next(r for r in response.results if r["status"] == "new")
- assert sum(new_series["data"]) == expected_new_count
-
- def test_days_of_week_actors_match_chart(self):
- # The actors query must honor daysOfWeek like the chart does, or the persons modal
- # would list people whose only events fall on deselected days
- self._create_events(
- data=[
- ("p_mon", ["2020-01-13T12:00:00Z"]), # Monday
- ("p_sat", ["2020-01-18T12:00:00Z"]), # Saturday
- ]
- )
- flush_persons_and_events()
-
- runner = self._create_query_runner("2020-01-13", "2020-01-19", IntervalType.DAY, days_of_week=[1])
-
- monday_new_actors = execute_hogql_query(
- team=self.team,
- query="SELECT actor_id FROM {actors_query}",
- placeholders={"actors_query": runner.to_actors_query(day="2020-01-13", status="new")},
- query_type="LifecycleActorsQuery",
- )
- saturday_new_actors = execute_hogql_query(
- team=self.team,
- query="SELECT actor_id FROM {actors_query}",
- placeholders={"actors_query": runner.to_actors_query(day="2020-01-18", status="new")},
- query_type="LifecycleActorsQuery",
- )
-
- assert len(monday_new_actors.results) == 1
- assert len(saturday_new_actors.results) == 0
+ assertLifecycleResults(filtered.results, expected)
+ assertLifecycleResults(unfiltered.results, expected)
def test_lifecycle_query_rejects_empty_series(self):
query = LifecycleQuery(