From 955b93d1db79acfb35f40a9bee0c5a71ae3a3adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Mon, 9 Oct 2023 12:43:28 +0200 Subject: [PATCH 1/4] fix(batch-exports): Include properties in feature_enabled call --- posthog/batch_exports/http.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/posthog/batch_exports/http.py b/posthog/batch_exports/http.py index f7084d65db89c..8a10abe99d3b9 100644 --- a/posthog/batch_exports/http.py +++ b/posthog/batch_exports/http.py @@ -170,11 +170,20 @@ def create(self, validated_data: dict) -> BatchExport: destination_data = validated_data.pop("destination") team_id = self.context["team_id"] - if validated_data["interval"] not in ("hour", "day", "week") and not posthoganalytics.feature_enabled( - "high-frequency-batch-exports", - str(Team.objects.get(id=team_id).uuid), - ): - raise PermissionDenied("Higher frequency exports are not enabled for this team.") + if validated_data["interval"] not in ("hour", "day", "week"): + team = Team.objects.get(id=team_id) + + if not posthoganalytics.feature_enabled( + "high-frequency-batch-exports", + str(team.uuid), + groups={"organization": str(team.organization.id)}, + group_properties={ + "organization": {"id": str(team.organization.id), "created_at": team.organization.created_at} + }, + only_evaluate_locally=True, + send_feature_flag_events=False, + ): + raise PermissionDenied("Higher frequency exports are not enabled for this team.") destination = BatchExportDestination(**destination_data) batch_export = BatchExport(team_id=team_id, destination=destination, **validated_data) From 72b838d74412d298a61743cf495f68ec4596427e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Mon, 9 Oct 2023 13:15:59 +0200 Subject: [PATCH 2/4] fix(batch-exports): Add high frequency to frontend types --- frontend/src/scenes/batch_exports/utils.ts | 1 + frontend/src/types.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/scenes/batch_exports/utils.ts b/frontend/src/scenes/batch_exports/utils.ts index 4302f2dc65298..16ebf9d3176ef 100644 --- a/frontend/src/scenes/batch_exports/utils.ts +++ b/frontend/src/scenes/batch_exports/utils.ts @@ -4,6 +4,7 @@ export function intervalToFrequency(interval: BatchExportConfiguration['interval return { day: 'daily', hour: 'hourly', + 'every 5 minutes': 'every 5 minutes', }[interval] } diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 0ca801012d6ec..60df3f8f1cf04 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -3211,7 +3211,7 @@ export type BatchExportConfiguration = { id: string name: string destination: BatchExportDestination - interval: 'hour' | 'day' + interval: 'hour' | 'day' | 'every 5 minutes' created_at: string start_at: string | null end_at: string | null From 048bd5e5c032e8f359a3740265b96421e7977845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Mon, 9 Oct 2023 13:16:21 +0200 Subject: [PATCH 3/4] fix(batch-exports): Make call not local only --- posthog/batch_exports/http.py | 1 - 1 file changed, 1 deletion(-) diff --git a/posthog/batch_exports/http.py b/posthog/batch_exports/http.py index 8a10abe99d3b9..cd8e24aca5cd6 100644 --- a/posthog/batch_exports/http.py +++ b/posthog/batch_exports/http.py @@ -180,7 +180,6 @@ def create(self, validated_data: dict) -> BatchExport: group_properties={ "organization": {"id": str(team.organization.id), "created_at": team.organization.created_at} }, - only_evaluate_locally=True, send_feature_flag_events=False, ): raise PermissionDenied("Higher frequency exports are not enabled for this team.") From 78fc9b8c18f188eb0215cb68ecebcf560256295e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Mon, 9 Oct 2023 13:16:32 +0200 Subject: [PATCH 4/4] fix(batch-exports): Update tests to reflect new feature_enabled calls --- posthog/api/test/batch_exports/test_create.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/posthog/api/test/batch_exports/test_create.py b/posthog/api/test/batch_exports/test_create.py index 3b63d3f3ceb7b..ca58d13a17347 100644 --- a/posthog/api/test/batch_exports/test_create.py +++ b/posthog/api/test/batch_exports/test_create.py @@ -65,7 +65,15 @@ def test_create_batch_export_with_interval_schedule(client: HttpClient, interval ) if interval == "every 5 minutes": - feature_enabled.assert_called_once_with("high-frequency-batch-exports", str(team.uuid)) + feature_enabled.assert_called_once_with( + "high-frequency-batch-exports", + str(team.uuid), + groups={"organization": str(team.organization.id)}, + group_properties={ + "organization": {"id": str(team.organization.id), "created_at": team.organization.created_at} + }, + send_feature_flag_events=False, + ) assert response.status_code == status.HTTP_201_CREATED, response.json() @@ -179,4 +187,12 @@ def test_cannot_create_a_batch_export_with_higher_frequencies_if_not_enabled(cli batch_export_data, ) assert response.status_code == status.HTTP_403_FORBIDDEN, response.json() - feature_enabled.assert_called_once_with("high-frequency-batch-exports", str(team.uuid)) + feature_enabled.assert_called_once_with( + "high-frequency-batch-exports", + str(team.uuid), + groups={"organization": str(team.organization.id)}, + group_properties={ + "organization": {"id": str(team.organization.id), "created_at": team.organization.created_at} + }, + send_feature_flag_events=False, + )