Skip to content

Commit

Permalink
feat(hogql): Add feature flag for opting queries into v3 query path
Browse files Browse the repository at this point in the history
  • Loading branch information
tkaemming committed Mar 26, 2024
1 parent fad9f5e commit 10faa58
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 11 additions & 3 deletions posthog/hogql/modifiers.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions posthog/models/team/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 10faa58

Please sign in to comment.