diff --git a/posthog/hogql/modifiers.py b/posthog/hogql/modifiers.py index 3c6fa11a9fc3b..8452016dc1411 100644 --- a/posthog/hogql/modifiers.py +++ b/posthog/hogql/modifiers.py @@ -1,7 +1,12 @@ from typing import Optional, TYPE_CHECKING -from posthog.schema import HogQLQueryModifiers, InCohortVia, MaterializationMode, PersonsArgMaxVersion -from posthog.utils import PersonOnEventsMode +from posthog.schema import ( + HogQLQueryModifiers, + InCohortVia, + MaterializationMode, + PersonsArgMaxVersion, + PersonsOnEventsMode, +) if TYPE_CHECKING: from posthog.models import Team @@ -16,7 +21,10 @@ def create_default_modifiers_for_team( modifiers = modifiers.model_copy() if modifiers.personsOnEventsMode is None: - modifiers.personsOnEventsMode = team.person_on_events_mode or PersonOnEventsMode.DISABLED + if team.person_on_events_v3_querying_enabled: + modifiers.personsOnEventsMode = PersonsOnEventsMode.v3_enabled + else: + modifiers.personsOnEventsMode = team.person_on_events_mode if modifiers.personsArgMaxVersion is None: modifiers.personsArgMaxVersion = PersonsArgMaxVersion.auto diff --git a/posthog/models/team/team.py b/posthog/models/team/team.py index 66b4a3ed51415..75dc98a0470ee 100644 --- a/posthog/models/team/team.py +++ b/posthog/models/team/team.py @@ -334,6 +334,22 @@ def _person_on_events_querying_enabled(self) -> bool: # on self-hosted, use the instance setting return get_instance_setting("PERSON_ON_EVENTS_ENABLED") + @property + def person_on_events_v3_querying_enabled(self) -> bool: + return posthoganalytics.feature_enabled( + "persons-on-events-v3-reads-enabled", + 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, + ) + @property def _person_on_events_v2_querying_enabled(self) -> bool: if settings.PERSON_ON_EVENTS_V2_OVERRIDE is not None: