From b4d5f25f22018e348b98ec53cfe3ed1dfeb9477d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Obermu=CC=88ller?= Date: Tue, 26 Sep 2023 22:17:57 +0200 Subject: [PATCH] use a feature flag condition based on user not team --- posthog/api/insight.py | 5 ++++- .../legacy_compatibility/feature_flag.py | 21 +++++++++++++++++++ posthog/models/team/team.py | 20 ------------------ 3 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 posthog/hogql_queries/legacy_compatibility/feature_flag.py diff --git a/posthog/api/insight.py b/posthog/api/insight.py index 3e0b4c534ad21..72db1fc457fde 100644 --- a/posthog/api/insight.py +++ b/posthog/api/insight.py @@ -53,6 +53,7 @@ from posthog.decorators import cached_by_filters from posthog.helpers.multi_property_breakdown import protect_old_clients_from_multi_property_default from posthog.hogql.errors import HogQLException +from posthog.hogql_queries.legacy_compatibility.feature_flag import hogql_insights_enabled from posthog.hogql_queries.legacy_compatibility.process_insight import is_insight_with_hogql_support, process_insight from posthog.kafka_client.topics import KAFKA_METRICS_TIME_TO_SEE_DATA from posthog.models import DashboardTile, Filter, Insight, User @@ -504,7 +505,9 @@ def insight_result(self, insight: Insight) -> InsightResult: dashboard_tile = self.dashboard_tile_from_context(insight, dashboard) target = insight if dashboard is None else dashboard_tile - if insight.team.hogql_insights_enabled and is_insight_with_hogql_support(target or insight): + if hogql_insights_enabled(self.context.get("request").user) and is_insight_with_hogql_support( + target or insight + ): return process_insight(target or insight, insight.team) is_shared = self.context.get("is_shared", False) diff --git a/posthog/hogql_queries/legacy_compatibility/feature_flag.py b/posthog/hogql_queries/legacy_compatibility/feature_flag.py new file mode 100644 index 0000000000000..f773dec5f3407 --- /dev/null +++ b/posthog/hogql_queries/legacy_compatibility/feature_flag.py @@ -0,0 +1,21 @@ +import posthoganalytics +from django.conf import settings +from posthog.cloud_utils import is_cloud +from posthog.models.user import User + + +def hogql_insights_enabled(user: User) -> bool: + if settings.HOGQL_INSIGHTS_OVERRIDE is not None: + return settings.HOGQL_INSIGHTS_OVERRIDE + + # on PostHog Cloud, use the feature flag + if is_cloud(): + return posthoganalytics.feature_enabled( + "hogql-insights", + user.distinct_id, + person_properties={"email": user.email}, + only_evaluate_locally=True, + send_feature_flag_events=False, + ) + else: + return False diff --git a/posthog/models/team/team.py b/posthog/models/team/team.py index 596f02e5a8528..73f1231d33bb0 100644 --- a/posthog/models/team/team.py +++ b/posthog/models/team/team.py @@ -275,26 +275,6 @@ def _person_on_events_v2_querying_enabled(self) -> bool: return get_instance_setting("PERSON_ON_EVENTS_V2_ENABLED") - @property - def hogql_insights_enabled(self) -> bool: - if settings.HOGQL_INSIGHTS_OVERRIDE is not None: - return settings.HOGQL_INSIGHTS_OVERRIDE - - # on PostHog Cloud, use the feature flag - if is_cloud(): - return posthoganalytics.feature_enabled( - "hogql-insights", - str(self.uuid), - groups={"organization": str(self.organization.id)}, - group_properties={ - "organization": {"id": str(self.organization.id), "created_at": self.organization.created_at} - }, - only_evaluate_locally=True, - send_feature_flag_events=False, - ) - else: - return False - @property def strict_caching_enabled(self) -> bool: enabled_teams = get_list(get_instance_setting("STRICT_CACHING_TEAMS"))