From b4a59fae777ba271ef1d5db0aea5a8a63747668c Mon Sep 17 00:00:00 2001 From: Rafa Audibert Date: Mon, 16 Dec 2024 14:24:01 -0300 Subject: [PATCH] chore: Use `DateRange` everywhere instead of `InsightDateRange` These are basically the same, the only difference is the default. Let's use `DateRange` without the default everywhere. If this proves to be a problem (too many broken tests) we can either:? 1. revert this 2. try to use it with the default on the places where we were not using a default before fix: Remove last references to `InsightDateRange` --- frontend/src/queries/schema.json | 62 +++-------- frontend/src/queries/schema.ts | 35 +----- .../database/schema/test/test_persons.py | 4 +- .../experiment_funnels_query_runner.py | 4 +- .../experiment_trends_query_runner.py | 16 +-- .../insights/funnels/test/test_funnel.py | 26 ++--- .../test_funnel_aggregation_operations.py | 18 ++-- .../funnels/test/test_funnel_trends_udf.py | 4 +- .../test/test_insight_actors_query_runner.py | 20 ++-- .../test/test_lifecycle_query_runner.py | 40 +++---- .../test/test_stickiness_query_runner.py | 4 +- .../insights/trends/test/test_trends.py | 4 +- .../test/test_trends_actors_query_builder.py | 12 +-- .../test/test_trends_dashboard_filters.py | 4 +- .../test/test_trends_data_warehouse_query.py | 20 ++-- .../trends/test/test_trends_persons.py | 102 +++++++++--------- .../trends/test/test_trends_query_builder.py | 8 +- .../trends/test/test_trends_query_runner.py | 4 +- .../legacy_compatibility/filter_to_query.py | 4 +- .../test/test_filter_to_query.py | 8 +- .../test/test_actors_query_runner.py | 4 +- .../utils/query_compare_to_date_range.py | 6 +- .../hogql_queries/utils/query_date_range.py | 8 +- .../utils/query_previous_period_date_range.py | 6 +- .../utils/test/test_query_date_range.py | 24 ++--- posthog/schema.py | 64 +++-------- .../test/test_trends_absolute_alerts.py | 6 +- .../test/test_trends_relative_alerts.py | 4 +- 28 files changed, 209 insertions(+), 312 deletions(-) diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json index e1b812e44e0e9..74e200cc47a49 100644 --- a/frontend/src/queries/schema.json +++ b/frontend/src/queries/schema.json @@ -726,7 +726,7 @@ "description": "Breakdown the chart by a property" }, "dateRange": { - "$ref": "#/definitions/AssistantInsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -1027,27 +1027,11 @@ } ] }, - "AssistantInsightDateRange": { - "additionalProperties": false, - "properties": { - "date_from": { - "default": "-7d", - "description": "Start date. The value can be:\n- a relative date. Examples of relative dates are: `-1y` for 1 year ago, `-14m` for 14 months ago, `-1w` for 1 week ago, `-14d` for 14 days ago, `-30h` for 30 hours ago.\n- an absolute ISO 8601 date string. a constant `yStart` for the current year start. a constant `mStart` for the current month start. a constant `dStart` for the current day start. Prefer using relative dates.", - "type": ["string", "null"] - }, - "date_to": { - "default": null, - "description": "Right boundary of the date range. Use `null` for the current date. You can not use relative dates here.", - "type": ["string", "null"] - } - }, - "type": "object" - }, "AssistantInsightsQueryBase": { "additionalProperties": false, "properties": { "dateRange": { - "$ref": "#/definitions/AssistantInsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -1349,7 +1333,7 @@ "description": "Compare to date range" }, "dateRange": { - "$ref": "#/definitions/AssistantInsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -6860,7 +6844,7 @@ "description": "Breakdown of the events and actions" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -7773,24 +7757,6 @@ }, "type": "object" }, - "InsightDateRange": { - "additionalProperties": false, - "properties": { - "date_from": { - "default": "-7d", - "type": ["string", "null"] - }, - "date_to": { - "type": ["string", "null"] - }, - "explicitDate": { - "default": false, - "description": "Whether the date_from and date_to should be used verbatim. Disables rounding to the start and end of period.", - "type": ["boolean", "null"] - } - }, - "type": "object" - }, "InsightFilter": { "anyOf": [ { @@ -7953,7 +7919,7 @@ "description": "Groups aggregation" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -8010,7 +7976,7 @@ "description": "Groups aggregation" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -8067,7 +8033,7 @@ "description": "Groups aggregation" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -8124,7 +8090,7 @@ "description": "Groups aggregation" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -8181,7 +8147,7 @@ "description": "Groups aggregation" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -8291,7 +8257,7 @@ "description": "Groups aggregation" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -8700,7 +8666,7 @@ "description": "Groups aggregation" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -11468,7 +11434,7 @@ "description": "Groups aggregation" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -12140,7 +12106,7 @@ "description": "Compare to date range" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { @@ -12691,7 +12657,7 @@ "description": "Whether we should be comparing against a specific conversion goal" }, "dateRange": { - "$ref": "#/definitions/InsightDateRange", + "$ref": "#/definitions/DateRange", "description": "Date range for the query" }, "filterTestAccounts": { diff --git a/frontend/src/queries/schema.ts b/frontend/src/queries/schema.ts index 0041753c3815e..0c03819d5d7df 100644 --- a/frontend/src/queries/schema.ts +++ b/frontend/src/queries/schema.ts @@ -819,7 +819,7 @@ interface InsightVizNodeViewProps { /** Base class for insight query nodes. Should not be used directly. */ export interface InsightsQueryBase> extends Node { /** Date range for the query */ - dateRange?: InsightDateRange + dateRange?: DateRange /** * Exclude internal and test users by applying the respective filters * @@ -1004,31 +1004,11 @@ export type AssistantGroupPropertyFilter = AssistantBasePropertyFilter & { export type AssistantPropertyFilter = AssistantGenericPropertyFilter | AssistantGroupPropertyFilter -export interface AssistantInsightDateRange { - /** - * Start date. The value can be: - * - a relative date. Examples of relative dates are: `-1y` for 1 year ago, `-14m` for 14 months ago, `-1w` for 1 week ago, `-14d` for 14 days ago, `-30h` for 30 hours ago. - * - an absolute ISO 8601 date string. - * a constant `yStart` for the current year start. - * a constant `mStart` for the current month start. - * a constant `dStart` for the current day start. - * Prefer using relative dates. - * @default -7d - */ - date_from?: string | null - - /** - * Right boundary of the date range. Use `null` for the current date. You can not use relative dates here. - * @default null - */ - date_to?: string | null -} - export interface AssistantInsightsQueryBase { /** * Date range for the query */ - dateRange?: AssistantInsightDateRange + dateRange?: DateRange /** * Exclude internal and test users by applying the respective filters @@ -2319,17 +2299,6 @@ export interface DateRange { explicitDate?: boolean | null } -export interface InsightDateRange { - /** @default -7d */ - date_from?: string | null - date_to?: string | null - /** Whether the date_from and date_to should be used verbatim. Disables - * rounding to the start and end of period. - * @default false - * */ - explicitDate?: boolean | null -} - export type MultipleBreakdownType = Extract export interface Breakdown { diff --git a/posthog/hogql/database/schema/test/test_persons.py b/posthog/hogql/database/schema/test/test_persons.py index e259df691d06e..164ff1be1cc5f 100644 --- a/posthog/hogql/database/schema/test/test_persons.py +++ b/posthog/hogql/database/schema/test/test_persons.py @@ -5,7 +5,7 @@ TrendsQuery, ActorsQuery, EventsNode, - InsightDateRange, + DateRange, ) from posthog.hogql_queries.actors_query_runner import ActorsQueryRunner from posthog.hogql.modifiers import create_default_modifiers_for_team @@ -102,7 +102,7 @@ def test_joins_are_left_alone_for_now(self): def test_person_modal_not_optimized_yet(self): source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="2024-01-01", date_to="2024-01-07"), + dateRange=DateRange(date_from="2024-01-01", date_to="2024-01-07"), # breakdownFilter=BreakdownFilter(breakdown="$", breakdown_type=BreakdownType.PERSON), ) insight_actors_query = InsightActorsQuery( diff --git a/posthog/hogql_queries/experiments/experiment_funnels_query_runner.py b/posthog/hogql_queries/experiments/experiment_funnels_query_runner.py index 69e12f49bbd13..d9d874d7b6e6b 100644 --- a/posthog/hogql_queries/experiments/experiment_funnels_query_runner.py +++ b/posthog/hogql_queries/experiments/experiment_funnels_query_runner.py @@ -20,7 +20,7 @@ FunnelsFilter, FunnelsQuery, FunnelsQueryResponse, - InsightDateRange, + DateRange, BreakdownFilter, ) from typing import Optional, Any, cast @@ -105,7 +105,7 @@ def _prepare_funnel_query(self) -> FunnelsQuery: start_date = self.experiment.start_date end_date = self.experiment.end_date - prepared_funnels_query.dateRange = InsightDateRange( + prepared_funnels_query.dateRange = DateRange( date_from=start_date.isoformat() if start_date else None, date_to=end_date.isoformat() if end_date else None, explicitDate=True, diff --git a/posthog/hogql_queries/experiments/experiment_trends_query_runner.py b/posthog/hogql_queries/experiments/experiment_trends_query_runner.py index 3bc9888021158..56c089d27cb9d 100644 --- a/posthog/hogql_queries/experiments/experiment_trends_query_runner.py +++ b/posthog/hogql_queries/experiments/experiment_trends_query_runner.py @@ -32,7 +32,7 @@ ExperimentTrendsQuery, ExperimentTrendsQueryResponse, ExperimentVariantTrendsBaseStats, - InsightDateRange, + DateRange, PropertyMathType, PropertyOperator, TrendsFilter, @@ -80,9 +80,9 @@ def _uses_math_aggregation_by_user_or_property_value(self, query: TrendsQuery): math_keys.remove("sum") return any(entity.math in math_keys for entity in query.series) - def _get_insight_date_range(self) -> InsightDateRange: + def _get_date_range(self) -> DateRange: """ - Returns an InsightDateRange object based on the experiment's start and end dates, + Returns an DateRange object based on the experiment's start and end dates, adjusted for the team's timezone if applicable. """ if self.team.timezone: @@ -93,7 +93,7 @@ def _get_insight_date_range(self) -> InsightDateRange: start_date = self.experiment.start_date end_date = self.experiment.end_date - return InsightDateRange( + return DateRange( date_from=start_date.isoformat() if start_date else None, date_to=end_date.isoformat() if end_date else None, explicitDate=True, @@ -133,7 +133,7 @@ def _prepare_count_query(self) -> TrendsQuery: prepared_count_query.series[0].math = None prepared_count_query.trendsFilter = TrendsFilter(display=ChartDisplayType.ACTIONS_LINE_GRAPH_CUMULATIVE) - prepared_count_query.dateRange = self._get_insight_date_range() + prepared_count_query.dateRange = self._get_date_range() if self._is_data_warehouse_query(prepared_count_query): prepared_count_query.breakdownFilter = self._get_data_warehouse_breakdown_filter() prepared_count_query.properties = [ @@ -182,7 +182,7 @@ def _prepare_exposure_query(self) -> TrendsQuery: if uses_math_aggregation: prepared_exposure_query = prepared_count_query - prepared_exposure_query.dateRange = self._get_insight_date_range() + prepared_exposure_query.dateRange = self._get_date_range() prepared_exposure_query.trendsFilter = TrendsFilter(display=ChartDisplayType.ACTIONS_LINE_GRAPH_CUMULATIVE) # For a data warehouse query, we can use the unique users for the series @@ -229,7 +229,7 @@ def _prepare_exposure_query(self) -> TrendsQuery: # 2. Otherwise, if an exposure query is provided, we use it as is, adapting the date range and breakdown elif self.query.exposure_query and not self._is_data_warehouse_query(prepared_count_query): prepared_exposure_query = TrendsQuery(**self.query.exposure_query.model_dump()) - prepared_exposure_query.dateRange = self._get_insight_date_range() + prepared_exposure_query.dateRange = self._get_date_range() prepared_exposure_query.trendsFilter = TrendsFilter(display=ChartDisplayType.ACTIONS_LINE_GRAPH_CUMULATIVE) prepared_exposure_query.breakdownFilter = self._get_event_breakdown_filter() prepared_exposure_query.properties = [ @@ -243,7 +243,7 @@ def _prepare_exposure_query(self) -> TrendsQuery: # 3. Otherwise, we construct a default exposure query: unique users for the $feature_flag_called event else: prepared_exposure_query = TrendsQuery( - dateRange=self._get_insight_date_range(), + dateRange=self._get_date_range(), trendsFilter=TrendsFilter(display=ChartDisplayType.ACTIONS_LINE_GRAPH_CUMULATIVE), breakdownFilter=BreakdownFilter( breakdown="$feature_flag_response", diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel.py b/posthog/hogql_queries/insights/funnels/test/test_funnel.py index 2c762f279331b..4cccf2c54414a 100644 --- a/posthog/hogql_queries/insights/funnels/test/test_funnel.py +++ b/posthog/hogql_queries/insights/funnels/test/test_funnel.py @@ -43,7 +43,7 @@ FunnelsFilter, FunnelsQuery, HogQLQueryModifiers, - InsightDateRange, + DateRange, PersonsOnEventsMode, PropertyOperator, FunnelMathType, @@ -3935,7 +3935,7 @@ def test_parses_breakdowns_correctly(self): query = FunnelsQuery( series=[EventsNode(event="$pageview"), EventsNode(event="$pageview")], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="2024-03-22", date_to="2024-03-22", ), @@ -3968,7 +3968,7 @@ def test_funnel_parses_event_names_correctly(self): query = FunnelsQuery( series=[EventsNode(event="test'1"), EventsNode()], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="2024-03-22", date_to="2024-03-22", ), @@ -4026,7 +4026,7 @@ def test_time_to_convert_funnel_ignores_breakdown(self): query = FunnelsQuery( series=[EventsNode(event="a"), EventsNode(event="b")], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="2024-03-22", date_to="2024-03-22", ), @@ -4066,7 +4066,7 @@ def test_first_time_for_user_funnel_basic(self): EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER), EventsNode(event="$pageview"), ], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="2024-03-22", date_to="2024-03-22", ), @@ -4081,7 +4081,7 @@ def test_first_time_for_user_funnel_basic(self): EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER), EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER), ], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="2024-03-22", date_to="2024-03-22", ), @@ -4148,7 +4148,7 @@ def test_first_time_for_user_funnel_with_actions(self): ActionsNode(id=action_credit_card.pk), ActionsNode(id=action_play_movie.pk, math=BaseMathType.FIRST_TIME_FOR_USER), ], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="-14d", ), ) @@ -4252,7 +4252,7 @@ def test_first_time_for_user_funnel_filters(self): EventsNode(event="$pageview"), EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER), ], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="2024-03-22", date_to="2024-03-22", ), @@ -4273,7 +4273,7 @@ def test_first_time_for_user_funnel_filters(self): ), EventsNode(event="$pageview"), ], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="2024-03-22", date_to="2024-03-22", ), @@ -4344,7 +4344,7 @@ def test_first_time_for_user_funnel_multiple_ids(self): EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER), EventsNode(event="$pageview"), ], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="2024-03-22", date_to="2024-03-22", ), @@ -4359,7 +4359,7 @@ def test_first_time_for_user_funnel_multiple_ids(self): EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER), EventsNode(event="$pageview"), ], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="2023-03-22", date_to="2024-03-22", ), @@ -4414,7 +4414,7 @@ def test_first_time_for_user_funnel_person_properties(self): ), EventsNode(event="event2"), ], - dateRange=InsightDateRange( + dateRange=DateRange( date_from="2024-03-20", date_to="2024-03-24", ), @@ -4462,7 +4462,7 @@ def test_funnel_personless_events_are_supported(self): query = FunnelsQuery( series=[EventsNode(event="$pageview"), EventsNode(event="sign up")], - dateRange=InsightDateRange(date_from="2024-03-22", date_to="2024-03-22"), + dateRange=DateRange(date_from="2024-03-22", date_to="2024-03-22"), ) results = FunnelsQueryRunner(query=query, team=self.team).calculate().results diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_aggregation_operations.py b/posthog/hogql_queries/insights/funnels/test/test_funnel_aggregation_operations.py index 1049b487ebcbb..5cfef9b468674 100644 --- a/posthog/hogql_queries/insights/funnels/test/test_funnel_aggregation_operations.py +++ b/posthog/hogql_queries/insights/funnels/test/test_funnel_aggregation_operations.py @@ -8,7 +8,7 @@ from posthog.hogql.parser import parse_expr from posthog.hogql_queries.insights.funnels.funnel_aggregation_operations import FirstTimeForUserAggregationQuery from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext -from posthog.schema import EventsNode, FunnelsFilter, FunnelsQuery, InsightDateRange +from posthog.schema import EventsNode, FunnelsFilter, FunnelsQuery, DateRange from posthog.test.base import APIBaseTest, ClickhouseTestMixin @@ -17,7 +17,7 @@ def test_first_time_for_user_aggregation_outer_query(self): funnels_query = FunnelsQuery( series=[EventsNode(event="$pageview")], funnelsFilter=FunnelsFilter(funnelWindowInterval=14), - dateRange=InsightDateRange(date_from="-14d"), + dateRange=DateRange(date_from="-14d"), ) ctx = FunnelQueryContext(funnels_query, self.team) filters = parse_expr("1 = 1") @@ -35,7 +35,7 @@ def test_first_time_for_user_aggregation_query_select(self): funnels_query = FunnelsQuery( series=[EventsNode(event="$pageview")], funnelsFilter=FunnelsFilter(funnelWindowInterval=14), - dateRange=InsightDateRange(date_from="-14d"), + dateRange=DateRange(date_from="-14d"), ) with freeze_time("2024-07-31"): @@ -88,7 +88,7 @@ def test_first_time_for_user_aggregation_query_filter(self): funnels_query = FunnelsQuery( series=[EventsNode(event="$pageview")], funnelsFilter=FunnelsFilter(funnelWindowInterval=14), - dateRange=InsightDateRange(date_from="-14d"), + dateRange=DateRange(date_from="-14d"), ) with freeze_time("2024-07-31"): @@ -115,7 +115,7 @@ def test_first_time_for_user_aggregation_query_no_filters(self): funnels_query = FunnelsQuery( series=[EventsNode(event="$pageview")], funnelsFilter=FunnelsFilter(funnelWindowInterval=14), - dateRange=InsightDateRange(date_from="-14d"), + dateRange=DateRange(date_from="-14d"), ) with freeze_time("2024-07-31"): @@ -143,7 +143,7 @@ def test_first_time_for_user_aggregation_query_group_by(self): funnels_query = FunnelsQuery( series=[EventsNode(event="$pageview")], funnelsFilter=FunnelsFilter(funnelWindowInterval=14), - dateRange=InsightDateRange(date_from="-14d"), + dateRange=DateRange(date_from="-14d"), ) ctx = FunnelQueryContext(funnels_query, self.team) @@ -161,7 +161,7 @@ def test_first_time_for_user_aggregation_query_having(self): funnels_query = FunnelsQuery( series=[EventsNode(event="$pageview")], funnelsFilter=FunnelsFilter(funnelWindowInterval=14), - dateRange=InsightDateRange(date_from="-14d"), + dateRange=DateRange(date_from="-14d"), ) ctx = FunnelQueryContext(funnels_query, self.team) @@ -183,7 +183,7 @@ def test_first_time_for_user_aggregation_query_sampling_factor(self): funnels_query = FunnelsQuery( series=[EventsNode(event="$pageview")], funnelsFilter=FunnelsFilter(funnelWindowInterval=14), - dateRange=InsightDateRange(date_from="-14d"), + dateRange=DateRange(date_from="-14d"), samplingFactor=0.1, ) ctx = FunnelQueryContext(funnels_query, self.team) @@ -202,7 +202,7 @@ def test_first_time_for_user_aggregation_query_select_from(self): funnels_query = FunnelsQuery( series=[EventsNode(event="$pageview")], funnelsFilter=FunnelsFilter(funnelWindowInterval=14), - dateRange=InsightDateRange(date_from="-14d"), + dateRange=DateRange(date_from="-14d"), ) ctx = FunnelQueryContext(funnels_query, self.team) diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_trends_udf.py b/posthog/hogql_queries/insights/funnels/test/test_funnel_trends_udf.py index 783bb30a53ab7..278344e75d714 100644 --- a/posthog/hogql_queries/insights/funnels/test/test_funnel_trends_udf.py +++ b/posthog/hogql_queries/insights/funnels/test/test_funnel_trends_udf.py @@ -17,7 +17,7 @@ FunnelsFilter, FunnelVizType, BreakdownAttributionType, - InsightDateRange, + DateRange, IntervalType, ) from posthog.test.base import _create_person, _create_event @@ -120,7 +120,7 @@ def test_different_prop_val_in_strict_filter(self): funnels_query = FunnelsQuery( series=[EventsNode(event="first"), EventsNode(event="second")], breakdownFilter=BreakdownFilter(breakdown="bd"), - dateRange=InsightDateRange(date_from="2024-01-01", date_to="2024-01-08"), + dateRange=DateRange(date_from="2024-01-01", date_to="2024-01-08"), interval=IntervalType.DAY, funnelsFilter=FunnelsFilter(funnelOrderType=FunnelOrderType.STRICT, funnelVizType=FunnelVizType.TRENDS), ) diff --git a/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py b/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py index 4c5f20ff4d73d..4140066c218ff 100644 --- a/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py +++ b/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py @@ -99,7 +99,7 @@ def test_insight_persons_lifecycle_query(self): } + dateRange={} series={[]} /> @@ -127,7 +127,7 @@ def test_insight_persons_lifecycle_query_week_monday(self): } + dateRange={} series={[]} /> @@ -155,7 +155,7 @@ def test_insight_persons_lifecycle_query_week_sunday(self): } + dateRange={} series={[]} /> @@ -179,7 +179,7 @@ def test_insight_persons_stickiness_query(self): } + dateRange={} series={[]} /> @@ -203,7 +203,7 @@ def test_insight_persons_stickiness_groups_query(self): } + dateRange={} series={[]} /> @@ -227,7 +227,7 @@ def test_insight_persons_trends_query_with_argmaxV1(self): } + dateRange={} series={[]} properties={[]} /> @@ -255,7 +255,7 @@ def test_insight_persons_trends_query_with_argmaxV2(self): } + dateRange={} series={[]} properties={[]} /> @@ -283,7 +283,7 @@ def test_insight_persons_trends_groups_query(self): } + dateRange={} series={[]} /> @@ -306,7 +306,7 @@ def test_insight_persons_funnels_query(self): } + dateRange={} series={[, ]} /> @@ -330,7 +330,7 @@ def test_insight_groups_funnels_query(self): } + dateRange={} series={[, ]} /> diff --git a/posthog/hogql_queries/insights/test/test_lifecycle_query_runner.py b/posthog/hogql_queries/insights/test/test_lifecycle_query_runner.py index 258f4bed96859..204deb37db23b 100644 --- a/posthog/hogql_queries/insights/test/test_lifecycle_query_runner.py +++ b/posthog/hogql_queries/insights/test/test_lifecycle_query_runner.py @@ -5,7 +5,7 @@ from posthog.models.team import WeekStartDay from posthog.models.utils import UUIDT from posthog.schema import ( - InsightDateRange, + DateRange, IntervalType, LifecycleQuery, EventsNode, @@ -61,7 +61,7 @@ def _create_events(self, data, event="$pageview"): def _create_query_runner(self, date_from, date_to, interval, aggregation_group_type_index) -> LifecycleQueryRunner: series = [EventsNode(event="$pageview")] query = LifecycleQuery( - dateRange=InsightDateRange(date_from=date_from, date_to=date_to), + dateRange=DateRange(date_from=date_from, date_to=date_to), interval=interval, series=series, aggregation_group_type_index=aggregation_group_type_index, @@ -641,7 +641,7 @@ def _create_test_events(self): def _create_query_runner(self, date_from, date_to, interval) -> LifecycleQueryRunner: series = [EventsNode(event="$pageview")] query = LifecycleQuery( - dateRange=InsightDateRange(date_from=date_from, date_to=date_to), + dateRange=DateRange(date_from=date_from, date_to=date_to), interval=interval, series=series, ) @@ -958,7 +958,7 @@ def test_lifecycle_trend(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[EventsNode(event="$pageview")], ), @@ -1008,7 +1008,7 @@ def test_lifecycle_trend_all_events(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[EventsNode(event=None)], ), @@ -1072,7 +1072,7 @@ def test_lifecycle_trend_with_zero_person_ids(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[EventsNode(event="$pageview")], ), @@ -1173,7 +1173,7 @@ def test_lifecycle_trend_prop_filtering(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[EventsNode(event="$pageview")], properties=[EventPropertyFilter(key="$number", value="1", operator=PropertyOperator.EXACT)], @@ -1198,7 +1198,7 @@ def test_lifecycle_trend_prop_filtering(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[ EventsNode( @@ -1304,7 +1304,7 @@ def test_lifecycle_trend_person_prop_filtering(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[ EventsNode( @@ -1373,7 +1373,7 @@ def test_lifecycle_trends_distinct_id_repeat(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[EventsNode(event="$pageview")], ), @@ -1418,7 +1418,7 @@ def test_lifecycle_trend_action(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[ActionsNode(id=pageview_action.pk)], ), @@ -1462,7 +1462,7 @@ def test_lifecycle_trend_all_time(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="all"), + dateRange=DateRange(date_from="all"), interval=IntervalType.DAY, series=[EventsNode(event="$pageview")], ), @@ -1509,7 +1509,7 @@ def test_lifecycle_trend_weeks_sunday(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-02-05T00:00:00Z", date_to="2020-03-09T00:00:00Z"), + dateRange=DateRange(date_from="2020-02-05T00:00:00Z", date_to="2020-03-09T00:00:00Z"), interval=IntervalType.WEEK, series=[EventsNode(event="$pageview")], ), @@ -1568,7 +1568,7 @@ def test_lifecycle_trend_weeks_monday(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-02-05T00:00:00Z", date_to="2020-03-09T00:00:00Z"), + dateRange=DateRange(date_from="2020-02-05T00:00:00Z", date_to="2020-03-09T00:00:00Z"), interval=IntervalType.WEEK, series=[EventsNode(event="$pageview")], ), @@ -1623,7 +1623,7 @@ def test_lifecycle_trend_months(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-02-01T00:00:00Z", date_to="2020-09-01T00:00:00Z"), + dateRange=DateRange(date_from="2020-02-01T00:00:00Z", date_to="2020-09-01T00:00:00Z"), interval=IntervalType.MONTH, series=[EventsNode(event="$pageview")], ), @@ -1666,7 +1666,7 @@ def test_filter_test_accounts(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[EventsNode(event="$pageview")], filterTestAccounts=True, @@ -1711,7 +1711,7 @@ def test_timezones(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12", date_to="2020-01-19"), + dateRange=DateRange(date_from="2020-01-12", date_to="2020-01-19"), interval=IntervalType.DAY, series=[EventsNode(event="$pageview")], ), @@ -1737,7 +1737,7 @@ def test_timezones(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12", date_to="2020-01-19"), + dateRange=DateRange(date_from="2020-01-12", date_to="2020-01-19"), interval=IntervalType.DAY, series=[EventsNode(event="$pageview")], ), @@ -1784,7 +1784,7 @@ def test_sampling(self): LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[EventsNode(event="$pageview")], samplingFactor=0.1, @@ -1831,7 +1831,7 @@ def test_cohort_filter(self): response = LifecycleQueryRunner( team=self.team, query=LifecycleQuery( - dateRange=InsightDateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), + dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), interval=IntervalType.DAY, series=[EventsNode(event="$pageview")], properties=[CohortPropertyFilter(value=cohort.pk)], diff --git a/posthog/hogql_queries/insights/test/test_stickiness_query_runner.py b/posthog/hogql_queries/insights/test/test_stickiness_query_runner.py index 394fdcf0142b3..bc4754d04e9b3 100644 --- a/posthog/hogql_queries/insights/test/test_stickiness_query_runner.py +++ b/posthog/hogql_queries/insights/test/test_stickiness_query_runner.py @@ -14,7 +14,7 @@ from posthog.schema import ( ActionsNode, CohortPropertyFilter, - InsightDateRange, + DateRange, ElementPropertyFilter, EmptyPropertyFilter, EventPropertyFilter, @@ -215,7 +215,7 @@ def _run_query( query = StickinessQuery( series=query_series, - dateRange=InsightDateRange(date_from=query_date_from, date_to=query_date_to), + dateRange=DateRange(date_from=query_date_from, date_to=query_date_to), interval=query_interval, properties=properties, stickinessFilter=filters, diff --git a/posthog/hogql_queries/insights/trends/test/test_trends.py b/posthog/hogql_queries/insights/trends/test/test_trends.py index 5fe2bc58cc261..04d4fc97fd312 100644 --- a/posthog/hogql_queries/insights/trends/test/test_trends.py +++ b/posthog/hogql_queries/insights/trends/test/test_trends.py @@ -48,7 +48,7 @@ BreakdownFilter, DataWarehouseNode, EventsNode, - InsightDateRange, + DateRange, PropertyGroupFilter, TrendsFilter, TrendsQuery, @@ -178,7 +178,7 @@ def convert_filter_to_trends_query(filter: Filter) -> TrendsQuery: series=series, kind="TrendsQuery", filterTestAccounts=filter.filter_test_accounts, - dateRange=InsightDateRange(date_from=filter_as_dict.get("date_from"), date_to=filter_as_dict.get("date_to")), + dateRange=DateRange(date_from=filter_as_dict.get("date_from"), date_to=filter_as_dict.get("date_to")), samplingFactor=filter.sampling_factor, aggregation_group_type_index=filter.aggregation_group_type_index, breakdownFilter=BreakdownFilter( diff --git a/posthog/hogql_queries/insights/trends/test/test_trends_actors_query_builder.py b/posthog/hogql_queries/insights/trends/test/test_trends_actors_query_builder.py index 4d3c66acae670..69e6642d54cc2 100644 --- a/posthog/hogql_queries/insights/trends/test/test_trends_actors_query_builder.py +++ b/posthog/hogql_queries/insights/trends/test/test_trends_actors_query_builder.py @@ -17,14 +17,14 @@ Compare, CompareFilter, EventsNode, - InsightDateRange, + DateRange, IntervalType, TrendsFilter, TrendsQuery, ) from posthog.test.base import BaseTest -default_query = TrendsQuery(series=[EventsNode(event="$pageview")], dateRange=InsightDateRange(date_from="-7d")) +default_query = TrendsQuery(series=[EventsNode(event="$pageview")], dateRange=DateRange(date_from="-7d")) class TestTrendsActorsQueryBuilder(BaseTest): @@ -339,9 +339,7 @@ def test_date_range_explicit_date_from(self): self.team.timezone = "Europe/Berlin" trends_query = default_query.model_copy( - update={ - "dateRange": InsightDateRange(date_from="2024-05-08T14:29:13.634000Z", date_to=None, explicitDate=True) - }, + update={"dateRange": DateRange(date_from="2024-05-08T14:29:13.634000Z", date_to=None, explicitDate=True)}, deep=True, ) with freeze_time("2024-05-08T15:32:00.000Z"): @@ -353,7 +351,7 @@ def test_date_range_explicit_date_from(self): def test_date_range_explicit_date_to(self): trends_query = default_query.model_copy( update={ - "dateRange": InsightDateRange( + "dateRange": DateRange( date_from="2024-05-08T14:29:13.634000Z", date_to="2024-05-08T14:32:57.692000Z", explicitDate=True ) }, @@ -370,7 +368,7 @@ def test_date_range_explicit_monthly_active_users_math(self): trends_query = default_query.model_copy( update={ "series": [EventsNode(event="$pageview", math=BaseMathType.MONTHLY_ACTIVE)], - "dateRange": InsightDateRange( + "dateRange": DateRange( date_from="2024-05-08T14:29:13.634000Z", date_to="2024-05-08T14:32:57.692000Z", explicitDate=True ), }, diff --git a/posthog/hogql_queries/insights/trends/test/test_trends_dashboard_filters.py b/posthog/hogql_queries/insights/trends/test/test_trends_dashboard_filters.py index e3513b4654abc..9ffecbd9baf5d 100644 --- a/posthog/hogql_queries/insights/trends/test/test_trends_dashboard_filters.py +++ b/posthog/hogql_queries/insights/trends/test/test_trends_dashboard_filters.py @@ -6,7 +6,7 @@ ActionsNode, BreakdownFilter, DashboardFilter, - InsightDateRange, + DateRange, EventPropertyFilter, EventsNode, FilterLogicalOperator, @@ -40,7 +40,7 @@ def _create_query_runner( ) -> TrendsQueryRunner: query_series: list[EventsNode | ActionsNode] = [EventsNode(event="$pageview")] if series is None else series query = TrendsQuery( - dateRange=InsightDateRange(date_from=date_from, date_to=date_to, explicitDate=explicit_date), + dateRange=DateRange(date_from=date_from, date_to=date_to, explicitDate=explicit_date), interval=interval, series=query_series, trendsFilter=trends_filters, diff --git a/posthog/hogql_queries/insights/trends/test/test_trends_data_warehouse_query.py b/posthog/hogql_queries/insights/trends/test/test_trends_data_warehouse_query.py index 63b4c8e276993..6f8f52af5f2e5 100644 --- a/posthog/hogql_queries/insights/trends/test/test_trends_data_warehouse_query.py +++ b/posthog/hogql_queries/insights/trends/test/test_trends_data_warehouse_query.py @@ -11,7 +11,7 @@ BreakdownFilter, BreakdownType, ChartDisplayType, - InsightDateRange, + DateRange, DataWarehouseNode, DataWarehouseEventsModifier, TrendsQuery, @@ -160,7 +160,7 @@ def test_trends_data_warehouse(self): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[ DataWarehouseNode( id=table_name, @@ -185,7 +185,7 @@ def test_trends_entity_property(self): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[ DataWarehouseNode( id=table_name, @@ -211,7 +211,7 @@ def test_trends_query_properties(self): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[ DataWarehouseNode( id=table_name, @@ -237,7 +237,7 @@ def test_trends_breakdown(self): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[ DataWarehouseNode( id=table_name, @@ -311,7 +311,7 @@ def test_trends_breakdown_with_event_property(self): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[ DataWarehouseNode( id=table_name, @@ -368,7 +368,7 @@ def test_trends_breakdown_on_view(self): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[ DataWarehouseNode( id="saved_view", @@ -391,7 +391,7 @@ def test_trends_breakdown_with_property(self): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[ DataWarehouseNode( id=table_name, @@ -420,7 +420,7 @@ def assert_column_names_with_display_type(self, display_type: ChartDisplayType): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[ DataWarehouseNode( id=table_name, @@ -463,7 +463,7 @@ def test_trends_with_multiple_property_types(self): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[ DataWarehouseNode( id=table_name, diff --git a/posthog/hogql_queries/insights/trends/test/test_trends_persons.py b/posthog/hogql_queries/insights/trends/test/test_trends_persons.py index 6ef3306715682..aa78ee5b579f4 100644 --- a/posthog/hogql_queries/insights/trends/test/test_trends_persons.py +++ b/posthog/hogql_queries/insights/trends/test/test_trends_persons.py @@ -28,7 +28,7 @@ EventsNode, HogQLQueryModifiers, InsightActorsQuery, - InsightDateRange, + DateRange, IntervalType, MathGroupTypeIndex, MultipleBreakdownType, @@ -306,7 +306,7 @@ def test_trends_single_series_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-29") @@ -320,7 +320,7 @@ def test_trends_multiple_series_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview"), EventsNode(event="$pageleave")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-29") @@ -341,7 +341,7 @@ def test_trends_event_breakdown_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown="$browser"), ) @@ -361,7 +361,7 @@ def test_trends_person_breakdown_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown="$geoip_country_code", breakdown_type=BreakdownType.PERSON), ) @@ -382,7 +382,7 @@ def test_trends_breakdown_others_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown="$browser", breakdown_limit=1), ) @@ -405,7 +405,7 @@ def test_trends_multiple_breakdowns_others_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdowns=[Breakdown(property="$browser")], breakdown_limit=1, @@ -431,7 +431,7 @@ def test_trends_filter_by_other(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdowns=[Breakdown(property="some_property", type=MultipleBreakdownType.EVENT)], breakdown_limit=1, @@ -443,7 +443,7 @@ def test_trends_filter_by_other(self): source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdowns=[ Breakdown(property="some_property", type=MultipleBreakdownType.EVENT), @@ -464,7 +464,7 @@ def test_trends_breakdown_null_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown="$browser", breakdown_limit=1), ) @@ -482,7 +482,7 @@ def test_trends_breakdown_hogql_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown="properties.some_property", breakdown_type=BreakdownType.HOGQL), ) @@ -504,7 +504,7 @@ def test_trends_cohort_breakdown_persons(self): ) source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown=[cohort.pk], breakdown_type=BreakdownType.COHORT), ) @@ -530,7 +530,7 @@ def test_trends_multi_cohort_breakdown_persons(self): ) source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown=[cohort1.pk, cohort2.pk], breakdown_type=BreakdownType.COHORT), ) @@ -557,7 +557,7 @@ def trends_all_cohort_breakdown_persons(self, inCohortVia: str): ) source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown=[cohort1.pk, "all"], breakdown_type=BreakdownType.COHORT), ) @@ -603,7 +603,7 @@ def test_trends_math_weekly_active_persons(self): ) source_query = TrendsQuery( series=[EventsNode(event="$pageview", math=BaseMathType.WEEKLY_ACTIVE)], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-28") @@ -618,7 +618,7 @@ def test_trends_math_property_sum_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview", math=PropertyMathType.SUM, math_property="some_property")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-05-01") @@ -640,7 +640,7 @@ def test_trends_math_count_per_actor_persons(self): event="$pageview", math=CountPerActorMathType.MAX_COUNT_PER_ACTOR, math_property="some_property" ) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-05-01") @@ -685,7 +685,7 @@ def test_trends_math_group_persons(self): series=[ EventsNode(event="$pageview", math="unique_group", math_group_type_index=MathGroupTypeIndex.NUMBER_0) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-05-01") @@ -720,7 +720,7 @@ def test_trends_math_group_persons_filters_empty(self): series=[ EventsNode(event="$pageview", math="unique_group", math_group_type_index=MathGroupTypeIndex.NUMBER_0) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-05-01") @@ -733,7 +733,7 @@ def test_trends_total_value_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), trendsFilter=TrendsFilter(display=ChartDisplayType.BOLD_NUMBER), ) @@ -751,7 +751,7 @@ def test_trends_compare_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), trendsFilter=TrendsFilter(), compareFilter=CompareFilter(compare=True), ) @@ -774,7 +774,7 @@ def test_trends_event_multiple_breakdowns_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdowns=[Breakdown(property="$browser")]), ) @@ -794,7 +794,7 @@ def test_trends_person_multiple_breakdown_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdowns=[Breakdown(property="$geoip_country_code", type=BreakdownType.PERSON)] ), @@ -816,7 +816,7 @@ def test_trends_multiple_breakdown_null_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdowns=[Breakdown(property="$browser")], breakdown_limit=1, @@ -839,7 +839,7 @@ def test_trends_multiple_breakdowns_hogql_persons(self): self._create_events() source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdowns=[Breakdown(property="properties.some_property", type=BreakdownType.HOGQL)], breakdown_limit=1, @@ -860,7 +860,7 @@ def test_trends_breakdown_filter_by_range(self): source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdown="some_property", breakdown_histogram_bin_count=4, @@ -895,7 +895,7 @@ def test_trends_multiple_breakdowns_filter_by_range(self): source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdowns=[Breakdown(property="some_property", histogram_bin_count=4)]), ) @@ -962,7 +962,7 @@ def test_trends_breakdown_by_boolean(self): source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdowns=[Breakdown(property="bool")], breakdown_limit=1, @@ -980,7 +980,7 @@ def test_trends_breakdown_by_boolean(self): source_query = TrendsQuery( series=[EventsNode(event="$pageview")], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdown="bool", breakdown_limit=1, @@ -1001,7 +1001,7 @@ def test_trends_math_first_time_for_user_basic(self): source_query = TrendsQuery( series=[EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER)], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) for i in range(4): @@ -1033,7 +1033,7 @@ def test_trends_math_first_time_for_user_breakdowns_basic(self): source_query = TrendsQuery( series=[EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER)], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown="$browser"), ) @@ -1057,7 +1057,7 @@ def test_trends_math_first_time_for_user_breakdowns_basic(self): source_query = TrendsQuery( series=[EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER)], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdowns=[Breakdown(property="$browser", type=MultipleBreakdownType.EVENT)] ), @@ -1087,7 +1087,7 @@ def test_trends_math_first_time_for_user_numeric_breakdowns(self): # single breakdown and bins source_query = TrendsQuery( series=[EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER)], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown="some_property", breakdown_histogram_bin_count=4), ) @@ -1112,7 +1112,7 @@ def test_trends_math_first_time_for_user_numeric_breakdowns(self): # single breakdown and just numbers source_query = TrendsQuery( series=[EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER)], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter(breakdown="some_property"), ) @@ -1127,7 +1127,7 @@ def test_trends_math_first_time_for_user_numeric_breakdowns(self): # multiple breakdowns and bins source_query = TrendsQuery( series=[EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER)], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdowns=[ Breakdown(property="some_property", type=MultipleBreakdownType.EVENT, histogram_bin_count=4) @@ -1156,7 +1156,7 @@ def test_trends_math_first_time_for_user_numeric_breakdowns(self): # multiple breakdowns and just numbers source_query = TrendsQuery( series=[EventsNode(event="$pageview", math=BaseMathType.FIRST_TIME_FOR_USER)], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), breakdownFilter=BreakdownFilter( breakdowns=[Breakdown(property="some_property", type=MultipleBreakdownType.EVENT)] ), @@ -1181,7 +1181,7 @@ def test_trends_math_first_time_for_user_with_filters(self): properties=[EventPropertyFilter(key="$browser", operator=PropertyOperator.EXACT, value="Chrome")], ) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-29") @@ -1201,7 +1201,7 @@ def test_trends_math_first_time_for_user_with_filters(self): ], ) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-29") @@ -1283,7 +1283,7 @@ def test_trends_math_first_time_for_user_handles_multiple_ids(self): math=BaseMathType.FIRST_TIME_FOR_USER, ) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), trendsFilter=TrendsFilter(display=ChartDisplayType.ACTIONS_LINE_GRAPH), ) @@ -1335,7 +1335,7 @@ def test_trends_math_first_time_for_user_matches_first_event_only(self): properties=[EventPropertyFilter(key="$browser", operator=PropertyOperator.EXACT, value="Chrome")], ) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2020-01-11") @@ -1353,7 +1353,7 @@ def test_trends_math_first_time_for_user_matches_first_event_only(self): properties=[EventPropertyFilter(key="$browser", operator=PropertyOperator.EXACT, value="Safari")], ) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2020-01-11") @@ -1396,7 +1396,7 @@ def test_trends_math_first_time_for_user_matches_all_first_events(self): properties=[EventPropertyFilter(key="$browser", operator=PropertyOperator.EXACT, value="Chrome")], ) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2020-01-11") @@ -1414,7 +1414,7 @@ def test_trends_math_first_time_for_user_matches_all_first_events(self): properties=[EventPropertyFilter(key="$browser", operator=PropertyOperator.EXACT, value="Safari")], ) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2020-01-11") @@ -1435,7 +1435,7 @@ def test_trends_math_first_time_for_user_month_interval(self): math=BaseMathType.FIRST_TIME_FOR_USER, ) ], - dateRange=InsightDateRange(date_from="-180d"), + dateRange=DateRange(date_from="-180d"), ) result = self._get_actors(trends_query=source_query, day="2023-03-01") @@ -1465,7 +1465,7 @@ def test_trends_math_first_time_for_user_day_interval(self): math=BaseMathType.FIRST_TIME_FOR_USER, ) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-29") @@ -1495,7 +1495,7 @@ def test_trends_math_first_time_for_user_week_interval(self): math=BaseMathType.FIRST_TIME_FOR_USER, ) ], - dateRange=InsightDateRange(date_from="-90d"), + dateRange=DateRange(date_from="-90d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-24") @@ -1525,7 +1525,7 @@ def test_trends_math_first_time_for_user_hour_interval(self): math=BaseMathType.FIRST_TIME_FOR_USER, ) ], - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-29T16:00:00Z") @@ -1563,7 +1563,7 @@ def test_trends_math_first_time_for_user_minute_interval(self): math=BaseMathType.FIRST_TIME_FOR_USER, ) ], - dateRange=InsightDateRange(date_from="-1h"), + dateRange=DateRange(date_from="-1h"), ) result = self._get_actors(trends_query=source_query, day="2023-04-29T16:00:00Z") @@ -1596,7 +1596,7 @@ def test_trends_math_first_time_for_user_all_events(self): source_query = TrendsQuery( interval=IntervalType.MONTH, series=[EventsNode(math=BaseMathType.FIRST_TIME_FOR_USER)], - dateRange=InsightDateRange(date_from="-180d"), + dateRange=DateRange(date_from="-180d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-01") @@ -1653,7 +1653,7 @@ def test_trends_math_first_time_for_user_actions(self): source_query = TrendsQuery( interval=IntervalType.MONTH, series=[ActionsNode(id=action.id, math=BaseMathType.FIRST_TIME_FOR_USER)], - dateRange=InsightDateRange(date_from="-180d"), + dateRange=DateRange(date_from="-180d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-01") @@ -1692,7 +1692,7 @@ def test_trends_math_first_time_for_user_actions(self): source_query = TrendsQuery( interval=IntervalType.MONTH, series=[ActionsNode(id=action.id, math=BaseMathType.FIRST_TIME_FOR_USER)], - dateRange=InsightDateRange(date_from="-180d"), + dateRange=DateRange(date_from="-180d"), ) result = self._get_actors(trends_query=source_query, day="2023-04-01") diff --git a/posthog/hogql_queries/insights/trends/test/test_trends_query_builder.py b/posthog/hogql_queries/insights/trends/test/test_trends_query_builder.py index 4826813cb54de..832c6932a0afd 100644 --- a/posthog/hogql_queries/insights/trends/test/test_trends_query_builder.py +++ b/posthog/hogql_queries/insights/trends/test/test_trends_query_builder.py @@ -11,7 +11,7 @@ BreakdownFilter, BreakdownType, ChartDisplayType, - InsightDateRange, + DateRange, DataWarehouseNode, EventsNode, HogQLQueryResponse, @@ -73,7 +73,7 @@ def get_response(self, trends_query: TrendsQuery) -> HogQLQueryResponse: def test_column_names(self): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[EventsNode(event="$pageview", math=BaseMathType.TOTAL)], ) @@ -85,7 +85,7 @@ def test_column_names(self): def assert_column_names_with_display_type(self, display_type: ChartDisplayType): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[EventsNode(event="$pageview")], trendsFilter=TrendsFilter(display=display_type), ) @@ -98,7 +98,7 @@ def assert_column_names_with_display_type(self, display_type: ChartDisplayType): def assert_column_names_with_display_type_and_breakdowns(self, display_type: ChartDisplayType): trends_query = TrendsQuery( kind="TrendsQuery", - dateRange=InsightDateRange(date_from="2023-01-01"), + dateRange=DateRange(date_from="2023-01-01"), series=[EventsNode(event="$pageview")], trendsFilter=TrendsFilter(display=display_type), breakdownFilter=BreakdownFilter(breakdown="$geoip_country_code", breakdown_type=BreakdownType.EVENT), diff --git a/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py b/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py index c3c7d04a71af6..11d7a183a266f 100644 --- a/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py +++ b/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py @@ -47,7 +47,7 @@ EventsNode, HogQLQueryModifiers, InCohortVia, - InsightDateRange, + DateRange, IntervalType, MultipleBreakdownType, PersonPropertyFilter, @@ -359,7 +359,7 @@ def _create_query_runner( ) -> TrendsQueryRunner: query_series: list[EventsNode | ActionsNode] = [EventsNode(event="$pageview")] if series is None else series query = TrendsQuery( - dateRange=InsightDateRange(date_from=date_from, date_to=date_to, explicitDate=explicit_date), + dateRange=DateRange(date_from=date_from, date_to=date_to, explicitDate=explicit_date), interval=interval, series=query_series, trendsFilter=trends_filters, diff --git a/posthog/hogql_queries/legacy_compatibility/filter_to_query.py b/posthog/hogql_queries/legacy_compatibility/filter_to_query.py index 3439983291d68..42ca783b04bf1 100644 --- a/posthog/hogql_queries/legacy_compatibility/filter_to_query.py +++ b/posthog/hogql_queries/legacy_compatibility/filter_to_query.py @@ -22,7 +22,7 @@ FunnelsFilter, FunnelsQuery, FunnelVizType, - InsightDateRange, + DateRange, LifecycleFilter, LifecycleQuery, PathsFilter, @@ -277,7 +277,7 @@ class StickinessQueryWithTemplateVariables(StickinessQuery): def _date_range(filter: dict): - date_range = InsightDateRange( + date_range = DateRange( date_from=filter.get("date_from"), date_to=filter.get("date_to"), explicitDate=str_to_bool(filter.get("explicit_date")) if filter.get("explicit_date") else None, diff --git a/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py b/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py index 6b98d3d017093..9ba7c48f80c2a 100644 --- a/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py +++ b/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py @@ -32,7 +32,7 @@ FunnelVizType, GroupPropertyFilter, HogQLPropertyFilter, - InsightDateRange, + DateRange, Key, LifecycleFilter, LifecycleQuery, @@ -971,7 +971,7 @@ def test_date_range(self): query = filter_to_query(filter) - assert isinstance(query.dateRange, InsightDateRange) + assert isinstance(query.dateRange, DateRange) self.assertEqual(query.dateRange.date_from, "-14d") self.assertEqual(query.dateRange.date_to, "-7d") @@ -980,7 +980,7 @@ def test_date_range_with_explict_date_setting(self): query = filter_to_query(filter) - assert isinstance(query.dateRange, InsightDateRange) + assert isinstance(query.dateRange, DateRange) self.assertEqual(query.dateRange.date_from, "-14d") self.assertEqual(query.dateRange.date_to, "-7d") self.assertEqual(query.dateRange.explicitDate, True) @@ -1605,7 +1605,7 @@ def test_paths_filter(self): filterTestAccounts=True, funnelsFilter=FunnelsFilter(funnelVizType=FunnelVizType.STEPS, exclusions=[]), breakdownFilter=BreakdownFilter(), - dateRange=InsightDateRange(), + dateRange=DateRange(), ), funnelStep=2, ), diff --git a/posthog/hogql_queries/test/test_actors_query_runner.py b/posthog/hogql_queries/test/test_actors_query_runner.py index 730507e206f45..889896ae239a5 100644 --- a/posthog/hogql_queries/test/test_actors_query_runner.py +++ b/posthog/hogql_queries/test/test_actors_query_runner.py @@ -14,7 +14,7 @@ PropertyOperator, HogQLQuery, LifecycleQuery, - InsightDateRange, + DateRange, EventsNode, IntervalType, InsightActorsQuery, @@ -227,7 +227,7 @@ def test_source_lifecycle_query(self): ) ], interval=IntervalType.DAY, - dateRange=InsightDateRange(date_from="-7d"), + dateRange=DateRange(date_from="-7d"), ) query = ActorsQuery( select=["properties.email"], diff --git a/posthog/hogql_queries/utils/query_compare_to_date_range.py b/posthog/hogql_queries/utils/query_compare_to_date_range.py index b05d977640e69..b72503e39d03a 100644 --- a/posthog/hogql_queries/utils/query_compare_to_date_range.py +++ b/posthog/hogql_queries/utils/query_compare_to_date_range.py @@ -3,7 +3,7 @@ from posthog.hogql_queries.utils.query_date_range import QueryDateRange from posthog.models.team import Team -from posthog.schema import DateRange, IntervalType, InsightDateRange +from posthog.schema import DateRange, IntervalType from posthog.utils import ( relative_date_parse, ) @@ -13,14 +13,14 @@ class QueryCompareToDateRange(QueryDateRange): """Moves the start of a date range back by the compare_to interval and sets the end to have the same delta as the original""" _team: Team - _date_range: Optional[InsightDateRange | DateRange] + _date_range: Optional[DateRange] _interval: Optional[IntervalType] _now_without_timezone: datetime _compare_to: str def __init__( self, - date_range: Optional[InsightDateRange | DateRange], + date_range: Optional[DateRange], team: Team, interval: Optional[IntervalType], now: datetime, diff --git a/posthog/hogql_queries/utils/query_date_range.py b/posthog/hogql_queries/utils/query_date_range.py index 46fa611b6fee1..fbceab9f9b845 100644 --- a/posthog/hogql_queries/utils/query_date_range.py +++ b/posthog/hogql_queries/utils/query_date_range.py @@ -9,7 +9,7 @@ from posthog.hogql.parser import ast from posthog.models.team import Team, WeekStartDay from posthog.queries.util import get_earliest_timestamp, get_trunc_func_ch -from posthog.schema import DateRange, InsightDateRange, IntervalType +from posthog.schema import DateRange, IntervalType from posthog.utils import ( DEFAULT_DATE_FROM_DAYS, relative_date_parse, @@ -24,13 +24,13 @@ class QueryDateRange: """Translation of the raw `date_from` and `date_to` filter values to datetimes.""" _team: Team - _date_range: Optional[InsightDateRange | DateRange] + _date_range: Optional[DateRange] _interval: Optional[IntervalType] _now_without_timezone: datetime def __init__( self, - date_range: Optional[InsightDateRange | DateRange], + date_range: Optional[DateRange], team: Team, interval: Optional[IntervalType], now: datetime, @@ -285,7 +285,7 @@ def to_placeholders(self) -> dict[str, ast.Expr]: class QueryDateRangeWithIntervals(QueryDateRange): def __init__( self, - date_range: Optional[InsightDateRange], + date_range: Optional[DateRange], total_intervals: int, team: Team, interval: Optional[IntervalType], diff --git a/posthog/hogql_queries/utils/query_previous_period_date_range.py b/posthog/hogql_queries/utils/query_previous_period_date_range.py index df1ef53d4e069..c6dca63dc7d95 100644 --- a/posthog/hogql_queries/utils/query_previous_period_date_range.py +++ b/posthog/hogql_queries/utils/query_previous_period_date_range.py @@ -3,7 +3,7 @@ from posthog.hogql_queries.utils.query_date_range import QueryDateRange from posthog.models.team import Team -from posthog.schema import DateRange, InsightDateRange, IntervalType +from posthog.schema import DateRange, IntervalType from posthog.utils import ( get_compare_period_dates, relative_date_parse_with_delta_mapping, @@ -15,13 +15,13 @@ class QueryPreviousPeriodDateRange(QueryDateRange): """Translation of the raw `date_from` and `date_to` filter values to datetimes.""" _team: Team - _date_range: Optional[InsightDateRange | DateRange] + _date_range: Optional[DateRange] _interval: Optional[IntervalType] _now_without_timezone: datetime def __init__( self, - date_range: Optional[InsightDateRange | DateRange], + date_range: Optional[DateRange], team: Team, interval: Optional[IntervalType], now: datetime, diff --git a/posthog/hogql_queries/utils/test/test_query_date_range.py b/posthog/hogql_queries/utils/test/test_query_date_range.py index c87c29ebcbd72..4c260fdd4f913 100644 --- a/posthog/hogql_queries/utils/test/test_query_date_range.py +++ b/posthog/hogql_queries/utils/test/test_query_date_range.py @@ -5,21 +5,21 @@ from posthog.hogql import ast from posthog.hogql_queries.utils.query_date_range import QueryDateRange, QueryDateRangeWithIntervals from posthog.models.team import WeekStartDay -from posthog.schema import InsightDateRange, IntervalType +from posthog.schema import DateRange, IntervalType from posthog.test.base import APIBaseTest class TestQueryDateRange(APIBaseTest): def test_parsed_date(self): now = parser.isoparse("2021-08-25T00:00:00.000Z") - date_range = InsightDateRange(date_from="-48h") + date_range = DateRange(date_from="-48h") query_date_range = QueryDateRange(team=self.team, date_range=date_range, interval=IntervalType.DAY, now=now) self.assertEqual(query_date_range.date_from(), parser.isoparse("2021-08-23T00:00:00Z")) self.assertEqual(query_date_range.date_to(), parser.isoparse("2021-08-25T23:59:59.999999Z")) def test_parsed_date_hour(self): now = parser.isoparse("2021-08-25T00:00:00.000Z") - date_range = InsightDateRange(date_from="-48h") + date_range = DateRange(date_from="-48h") query_date_range = QueryDateRange(team=self.team, date_range=date_range, interval=IntervalType.HOUR, now=now) self.assertEqual(query_date_range.date_from(), parser.isoparse("2021-08-23T00:00:00Z")) @@ -29,7 +29,7 @@ def test_parsed_date_hour(self): def test_parsed_date_middle_of_hour(self): now = parser.isoparse("2021-08-25T00:00:00.000Z") - date_range = InsightDateRange(date_from="2021-08-23 05:00:00", date_to="2021-08-26 07:00:00") + date_range = DateRange(date_from="2021-08-23 05:00:00", date_to="2021-08-26 07:00:00") query_date_range = QueryDateRange(team=self.team, date_range=date_range, interval=IntervalType.HOUR, now=now) self.assertEqual(query_date_range.date_from(), parser.isoparse("2021-08-23 05:00:00Z")) @@ -39,7 +39,7 @@ def test_parsed_date_middle_of_hour(self): def test_parsed_date_week(self): now = parser.isoparse("2021-08-25T00:00:00.000Z") - date_range = InsightDateRange(date_from="-7d") + date_range = DateRange(date_from="-7d") query_date_range = QueryDateRange(team=self.team, date_range=date_range, interval=IntervalType.WEEK, now=now) self.assertEqual(query_date_range.date_from(), parser.isoparse("2021-08-18 00:00:00Z")) @@ -49,13 +49,13 @@ def test_all_values(self): now = parser.isoparse("2021-08-25T00:00:00.000Z") self.assertEqual( QueryDateRange( - team=self.team, date_range=InsightDateRange(date_from="-20h"), interval=IntervalType.DAY, now=now + team=self.team, date_range=DateRange(date_from="-20h"), interval=IntervalType.DAY, now=now ).all_values(), [parser.isoparse("2021-08-24T00:00:00Z"), parser.isoparse("2021-08-25T00:00:00Z")], ) self.assertEqual( QueryDateRange( - team=self.team, date_range=InsightDateRange(date_from="-20d"), interval=IntervalType.WEEK, now=now + team=self.team, date_range=DateRange(date_from="-20d"), interval=IntervalType.WEEK, now=now ).all_values(), [ parser.isoparse("2021-08-01T00:00:00Z"), @@ -67,7 +67,7 @@ def test_all_values(self): self.team.week_start_day = WeekStartDay.MONDAY self.assertEqual( QueryDateRange( - team=self.team, date_range=InsightDateRange(date_from="-20d"), interval=IntervalType.WEEK, now=now + team=self.team, date_range=DateRange(date_from="-20d"), interval=IntervalType.WEEK, now=now ).all_values(), [ parser.isoparse("2021-08-02T00:00:00Z"), @@ -78,13 +78,13 @@ def test_all_values(self): ) self.assertEqual( QueryDateRange( - team=self.team, date_range=InsightDateRange(date_from="-50d"), interval=IntervalType.MONTH, now=now + team=self.team, date_range=DateRange(date_from="-50d"), interval=IntervalType.MONTH, now=now ).all_values(), [parser.isoparse("2021-07-01T00:00:00Z"), parser.isoparse("2021-08-01T00:00:00Z")], ) self.assertEqual( QueryDateRange( - team=self.team, date_range=InsightDateRange(date_from="-3h"), interval=IntervalType.HOUR, now=now + team=self.team, date_range=DateRange(date_from="-3h"), interval=IntervalType.HOUR, now=now ).all_values(), [ parser.isoparse("2021-08-24T21:00:00Z"), @@ -96,7 +96,7 @@ def test_all_values(self): def test_date_to_explicit(self): now = parser.isoparse("2021-08-25T00:00:00.000Z") - date_range = InsightDateRange( + date_range = DateRange( date_from="2021-02-25T12:25:23.000Z", date_to="2021-04-25T10:59:23.000Z", explicitDate=True ) query_date_range = QueryDateRange(team=self.team, date_range=date_range, interval=IntervalType.DAY, now=now) @@ -106,7 +106,7 @@ def test_date_to_explicit(self): def test_yesterday(self): now = parser.isoparse("2021-08-25T00:00:00.000Z") - date_range = InsightDateRange(date_from="-1dStart", date_to="-1dEnd", explicitDate=False) + date_range = DateRange(date_from="-1dStart", date_to="-1dEnd", explicitDate=False) query_date_range = QueryDateRange(team=self.team, date_range=date_range, interval=IntervalType.HOUR, now=now) diff --git a/posthog/schema.py b/posthog/schema.py index 4dffd661f9895..9565200dfd859 100644 --- a/posthog/schema.py +++ b/posthog/schema.py @@ -204,27 +204,6 @@ class AssistantGroupPropertyFilter3(BaseModel): value: str = Field(..., description="Value must be a date in ISO 8601 format.") -class AssistantInsightDateRange(BaseModel): - model_config = ConfigDict( - extra="forbid", - ) - date_from: Optional[str] = Field( - default="-7d", - description=( - "Start date. The value can be:\n- a relative date. Examples of relative dates are: `-1y` for 1 year ago," - " `-14m` for 14 months ago, `-1w` for 1 week ago, `-14d` for 14 days ago, `-30h` for 30 hours ago.\n- an" - " absolute ISO 8601 date string. a constant `yStart` for the current year start. a constant `mStart` for" - " the current month start. a constant `dStart` for the current day start. Prefer using relative dates." - ), - ) - date_to: Optional[str] = Field( - default=None, - description=( - "Right boundary of the date range. Use `null` for the current date. You can not use relative dates here." - ), - ) - - class AssistantMessage(BaseModel): model_config = ConfigDict( extra="forbid", @@ -1087,21 +1066,6 @@ class DayItem(BaseModel): value: Union[str, AwareDatetime, int] -class InsightDateRange(BaseModel): - model_config = ConfigDict( - extra="forbid", - ) - date_from: Optional[str] = "-7d" - date_to: Optional[str] = None - explicitDate: Optional[bool] = Field( - default=False, - description=( - "Whether the date_from and date_to should be used verbatim. Disables rounding to the start and end of" - " period." - ), - ) - - class InsightFilterProperty(StrEnum): TRENDS_FILTER = "trendsFilter" FUNNELS_FILTER = "funnelsFilter" @@ -3567,7 +3531,7 @@ class AssistantFunnelsQuery(BaseModel): breakdownFilter: Optional[AssistantFunnelsBreakdownFilter] = Field( default=None, description="Breakdown the chart by a property" ) - dateRange: Optional[AssistantInsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -3606,7 +3570,7 @@ class AssistantInsightsQueryBase(BaseModel): model_config = ConfigDict( extra="forbid", ) - dateRange: Optional[AssistantInsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -3684,7 +3648,7 @@ class AssistantTrendsQuery(BaseModel): default=None, description="Breakdown of the events" ) compareFilter: Optional[CompareFilter] = Field(default=None, description="Compare to date range") - dateRange: Optional[AssistantInsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -5719,7 +5683,7 @@ class RetentionQuery(BaseModel): extra="forbid", ) aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation") - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -5767,7 +5731,7 @@ class StickinessQuery(BaseModel): extra="forbid", ) compareFilter: Optional[CompareFilter] = Field(default=None, description="Compare to date range") - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -5821,7 +5785,7 @@ class TrendsQuery(BaseModel): conversionGoal: Optional[Union[ActionConversionGoal, CustomEventConversionGoal]] = Field( default=None, description="Whether we should be comparing against a specific conversion goal" ) - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -6020,7 +5984,7 @@ class FunnelsQuery(BaseModel): ) aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation") breakdownFilter: Optional[BreakdownFilter] = Field(default=None, description="Breakdown of the events and actions") - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -6072,7 +6036,7 @@ class InsightsQueryBaseFunnelsQueryResponse(BaseModel): extra="forbid", ) aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation") - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -6111,7 +6075,7 @@ class InsightsQueryBaseLifecycleQueryResponse(BaseModel): extra="forbid", ) aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation") - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -6150,7 +6114,7 @@ class InsightsQueryBasePathsQueryResponse(BaseModel): extra="forbid", ) aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation") - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -6189,7 +6153,7 @@ class InsightsQueryBaseRetentionQueryResponse(BaseModel): extra="forbid", ) aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation") - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -6228,7 +6192,7 @@ class InsightsQueryBaseTrendsQueryResponse(BaseModel): extra="forbid", ) aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation") - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -6267,7 +6231,7 @@ class LifecycleQuery(BaseModel): extra="forbid", ) aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation") - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) @@ -6610,7 +6574,7 @@ class PathsQuery(BaseModel): extra="forbid", ) aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation") - dateRange: Optional[InsightDateRange] = Field(default=None, description="Date range for the query") + dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query") filterTestAccounts: Optional[bool] = Field( default=False, description="Exclude internal and test users by applying the respective filters" ) diff --git a/posthog/tasks/alerts/test/test_trends_absolute_alerts.py b/posthog/tasks/alerts/test/test_trends_absolute_alerts.py index 9a65a4297f978..1536c81885ca2 100644 --- a/posthog/tasks/alerts/test/test_trends_absolute_alerts.py +++ b/posthog/tasks/alerts/test/test_trends_absolute_alerts.py @@ -17,7 +17,7 @@ TrendsQuery, TrendsFilter, IntervalType, - InsightDateRange, + DateRange, BaseMathType, AlertState, AlertCalculationInterval, @@ -86,7 +86,7 @@ def create_time_series_trend_insight( breakdownFilter=breakdown, trendsFilter=TrendsFilter(display=ChartDisplayType.ACTIONS_LINE_GRAPH), interval=interval, - dateRange=InsightDateRange(date_from="-8w"), + dateRange=DateRange(date_from="-8w"), ).model_dump() insight = self.dashboard_api.create_insight( @@ -114,7 +114,7 @@ def create_aggregate_trend_insight(self, breakdown: Optional[BreakdownFilter] = breakdownFilter=breakdown, trendsFilter=TrendsFilter(display=ChartDisplayType.ACTIONS_PIE), interval=IntervalType.WEEK, - dateRange=InsightDateRange(date_from="-8w"), + dateRange=DateRange(date_from="-8w"), ).model_dump() insight = self.dashboard_api.create_insight( diff --git a/posthog/tasks/alerts/test/test_trends_relative_alerts.py b/posthog/tasks/alerts/test/test_trends_relative_alerts.py index b213ea2c47e54..8de118c8cce5e 100644 --- a/posthog/tasks/alerts/test/test_trends_relative_alerts.py +++ b/posthog/tasks/alerts/test/test_trends_relative_alerts.py @@ -17,7 +17,7 @@ TrendsQuery, TrendsFilter, IntervalType, - InsightDateRange, + DateRange, BaseMathType, AlertState, AlertCalculationInterval, @@ -89,7 +89,7 @@ def create_time_series_trend_insight( breakdownFilter=breakdown, trendsFilter=TrendsFilter(display=ChartDisplayType.ACTIONS_LINE_GRAPH), interval=interval, - dateRange=InsightDateRange(date_from="-8w"), + dateRange=DateRange(date_from="-8w"), ).model_dump() insight = self.dashboard_api.create_insight(