diff --git a/ee/clickhouse/models/test/test_cohort.py b/ee/clickhouse/models/test/test_cohort.py index 51ff0f2e8816f..00140e21f690d 100644 --- a/ee/clickhouse/models/test/test_cohort.py +++ b/ee/clickhouse/models/test/test_cohort.py @@ -16,6 +16,7 @@ from posthog.models.property.util import parse_prop_grouped_clauses from posthog.models.team import Team from posthog.queries.util import PersonPropertiesMode +from posthog.schema import PersonsOnEventsMode from posthog.test.base import ( BaseTest, ClickhouseTestMixin, @@ -25,7 +26,6 @@ snapshot_clickhouse_insert_cohortpeople_queries, snapshot_clickhouse_queries, ) -from posthog.utils import PersonOnEventsMode def _create_action(**kwargs): @@ -145,7 +145,7 @@ def test_prop_cohort_basic_action(self): team_id=self.team.pk, property_group=filter.property_groups, person_properties_mode=PersonPropertiesMode.USING_SUBQUERY - if self.team.person_on_events_mode == PersonOnEventsMode.DISABLED + if self.team.person_on_events_mode == PersonsOnEventsMode.disabled else PersonPropertiesMode.DIRECT_ON_EVENTS, hogql_context=filter.hogql_context, ) @@ -200,7 +200,7 @@ def test_prop_cohort_basic_event_days(self): team_id=self.team.pk, property_group=filter.property_groups, person_properties_mode=PersonPropertiesMode.USING_SUBQUERY - if self.team.person_on_events_mode == PersonOnEventsMode.DISABLED + if self.team.person_on_events_mode == PersonsOnEventsMode.disabled else PersonPropertiesMode.DIRECT_ON_EVENTS, hogql_context=filter.hogql_context, ) @@ -225,7 +225,7 @@ def test_prop_cohort_basic_event_days(self): team_id=self.team.pk, property_group=filter.property_groups, person_properties_mode=PersonPropertiesMode.USING_SUBQUERY - if self.team.person_on_events_mode == PersonOnEventsMode.DISABLED + if self.team.person_on_events_mode == PersonsOnEventsMode.disabled else PersonPropertiesMode.DIRECT_ON_EVENTS, hogql_context=filter.hogql_context, ) @@ -276,7 +276,7 @@ def test_prop_cohort_basic_action_days(self): team_id=self.team.pk, property_group=filter.property_groups, person_properties_mode=PersonPropertiesMode.USING_SUBQUERY - if self.team.person_on_events_mode == PersonOnEventsMode.DISABLED + if self.team.person_on_events_mode == PersonsOnEventsMode.disabled else PersonPropertiesMode.DIRECT_ON_EVENTS, hogql_context=filter.hogql_context, ) @@ -297,7 +297,7 @@ def test_prop_cohort_basic_action_days(self): team_id=self.team.pk, property_group=filter.property_groups, person_properties_mode=PersonPropertiesMode.USING_SUBQUERY - if self.team.person_on_events_mode == PersonOnEventsMode.DISABLED + if self.team.person_on_events_mode == PersonsOnEventsMode.disabled else PersonPropertiesMode.DIRECT_ON_EVENTS, hogql_context=filter.hogql_context, ) diff --git a/ee/clickhouse/queries/enterprise_cohort_query.py b/ee/clickhouse/queries/enterprise_cohort_query.py index a007b54903bdd..a748a64adf06a 100644 --- a/ee/clickhouse/queries/enterprise_cohort_query.py +++ b/ee/clickhouse/queries/enterprise_cohort_query.py @@ -12,7 +12,7 @@ validate_seq_date_more_recent_than_date, ) from posthog.queries.util import PersonPropertiesMode -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode def check_negation_clause(prop: PropertyGroup) -> Tuple[bool, bool]: @@ -319,7 +319,7 @@ def _get_sequence_query(self) -> Tuple[str, Dict[str, Any], str]: event_param_name = f"{self._cohort_pk}_event_ids" - if self.should_pushdown_persons and self._person_on_events_mode != PersonOnEventsMode.DISABLED: + if self.should_pushdown_persons and self._person_on_events_mode != PersonsOnEventsMode.disabled: person_prop_query, person_prop_params = self._get_prop_groups( self._inner_property_groups, person_properties_mode=PersonPropertiesMode.DIRECT_ON_EVENTS, diff --git a/ee/clickhouse/queries/event_query.py b/ee/clickhouse/queries/event_query.py index 3e57be3e3892f..259b4c4894786 100644 --- a/ee/clickhouse/queries/event_query.py +++ b/ee/clickhouse/queries/event_query.py @@ -12,7 +12,7 @@ from posthog.models.property import PropertyName from posthog.models.team import Team from posthog.queries.event_query.event_query import EventQuery -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class EnterpriseEventQuery(EventQuery): @@ -37,7 +37,7 @@ def __init__( extra_event_properties: List[PropertyName] = [], extra_person_fields: List[ColumnName] = [], override_aggregate_users_by_distinct_id: Optional[bool] = None, - person_on_events_mode: PersonOnEventsMode = PersonOnEventsMode.DISABLED, + person_on_events_mode: PersonsOnEventsMode = PersonsOnEventsMode.disabled, **kwargs, ) -> None: super().__init__( diff --git a/ee/clickhouse/queries/funnels/funnel_correlation.py b/ee/clickhouse/queries/funnels/funnel_correlation.py index ebe78d3b86826..3ca6801ee6af6 100644 --- a/ee/clickhouse/queries/funnels/funnel_correlation.py +++ b/ee/clickhouse/queries/funnels/funnel_correlation.py @@ -34,7 +34,8 @@ from posthog.queries.person_distinct_id_query import get_team_distinct_ids_query from posthog.queries.person_query import PersonQuery from posthog.queries.util import correct_result_for_sampling -from posthog.utils import PersonOnEventsMode, generate_short_id +from posthog.schema import PersonsOnEventsMode +from posthog.utils import generate_short_id class EventDefinition(TypedDict): @@ -155,7 +156,7 @@ def __init__( def properties_to_include(self) -> List[str]: props_to_include = [] if ( - self._team.person_on_events_mode != PersonOnEventsMode.DISABLED + self._team.person_on_events_mode != PersonsOnEventsMode.disabled and self._filter.correlation_type == FunnelCorrelationType.PROPERTIES ): # When dealing with properties, make sure funnel response comes with properties @@ -435,7 +436,7 @@ def get_properties_query(self) -> Tuple[str, Dict[str, Any]]: return query, params def _get_aggregation_target_join_query(self) -> str: - if self._team.person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + if self._team.person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: aggregation_person_join = f""" JOIN funnel_actors as actors ON event.person_id = actors.actor_id @@ -502,7 +503,7 @@ def _get_events_join_query(self) -> str: def _get_aggregation_join_query(self): if self._filter.aggregation_group_type_index is None: - if self._team.person_on_events_mode != PersonOnEventsMode.DISABLED and groups_on_events_querying_enabled(): + if self._team.person_on_events_mode != PersonsOnEventsMode.disabled and groups_on_events_querying_enabled(): return "", {} person_query, person_query_params = PersonQuery( @@ -522,7 +523,7 @@ def _get_aggregation_join_query(self): return GroupsJoinQuery(self._filter, self._team.pk, join_key="funnel_actors.actor_id").get_join_query() def _get_properties_prop_clause(self): - if self._team.person_on_events_mode != PersonOnEventsMode.DISABLED and groups_on_events_querying_enabled(): + if self._team.person_on_events_mode != PersonsOnEventsMode.disabled and groups_on_events_querying_enabled(): group_properties_field = f"group{self._filter.aggregation_group_type_index}_properties" aggregation_properties_alias = ( "person_properties" if self._filter.aggregation_group_type_index is None else group_properties_field @@ -549,7 +550,7 @@ def _get_properties_prop_clause(self): param_name = f"property_name_{index}" if self._filter.aggregation_group_type_index is not None: expression, _ = get_property_string_expr( - "groups" if self._team.person_on_events_mode == PersonOnEventsMode.DISABLED else "events", + "groups" if self._team.person_on_events_mode == PersonsOnEventsMode.disabled else "events", property_name, f"%({param_name})s", aggregation_properties_alias, @@ -557,12 +558,12 @@ def _get_properties_prop_clause(self): ) else: expression, _ = get_property_string_expr( - "person" if self._team.person_on_events_mode == PersonOnEventsMode.DISABLED else "events", + "person" if self._team.person_on_events_mode == PersonsOnEventsMode.disabled else "events", property_name, f"%({param_name})s", aggregation_properties_alias, materialised_table_column=aggregation_properties_alias - if self._team.person_on_events_mode != PersonOnEventsMode.DISABLED + if self._team.person_on_events_mode != PersonsOnEventsMode.disabled else "properties", ) person_property_params[param_name] = property_name diff --git a/ee/clickhouse/queries/groups_join_query.py b/ee/clickhouse/queries/groups_join_query.py index 886510dfc3541..db1d12a3c6c46 100644 --- a/ee/clickhouse/queries/groups_join_query.py +++ b/ee/clickhouse/queries/groups_join_query.py @@ -9,7 +9,7 @@ from posthog.models.property.util import parse_prop_grouped_clauses from posthog.models.team.team import groups_on_events_querying_enabled from posthog.queries.util import PersonPropertiesMode -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class GroupsJoinQuery: @@ -27,7 +27,7 @@ def __init__( team_id: int, column_optimizer: Optional[EnterpriseColumnOptimizer] = None, join_key: Optional[str] = None, - person_on_events_mode: PersonOnEventsMode = PersonOnEventsMode.DISABLED, + person_on_events_mode: PersonsOnEventsMode = PersonsOnEventsMode.disabled, ) -> None: self._filter = filter self._team_id = team_id @@ -38,7 +38,7 @@ def __init__( def get_join_query(self) -> Tuple[str, Dict]: join_queries, params = [], {} - if self._person_on_events_mode != PersonOnEventsMode.DISABLED and groups_on_events_querying_enabled(): + if self._person_on_events_mode != PersonsOnEventsMode.disabled and groups_on_events_querying_enabled(): return "", {} for group_type_index in self._column_optimizer.group_types_to_query: diff --git a/ee/session_recordings/queries/test/test_session_recording_list_from_session_replay.py b/ee/session_recordings/queries/test/test_session_recording_list_from_session_replay.py index 33fdd6c3e0236..71196ec0ecadc 100644 --- a/ee/session_recordings/queries/test/test_session_recording_list_from_session_replay.py +++ b/ee/session_recordings/queries/test/test_session_recording_list_from_session_replay.py @@ -12,6 +12,7 @@ from posthog.clickhouse.client import sync_execute from posthog.models import Person from posthog.models.filters import SessionRecordingsFilter +from posthog.schema import PersonsOnEventsMode from posthog.session_recordings.queries.session_recording_list_from_replay_summary import ( SessionRecordingListFromReplaySummary, ) @@ -24,7 +25,6 @@ snapshot_clickhouse_queries, _create_event, ) -from posthog.utils import PersonOnEventsMode @freeze_time("2021-01-01T13:46:23") @@ -63,7 +63,7 @@ def create_event( True, False, False, - PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS, + PersonsOnEventsMode.person_id_no_override_properties_on_events, { "kperson_filter_pre__0": "rgInternal", "kpersonquery_person_filter_fin__0": "rgInternal", @@ -79,7 +79,7 @@ def create_event( False, False, False, - PersonOnEventsMode.DISABLED, + PersonsOnEventsMode.disabled, { "kperson_filter_pre__0": "rgInternal", "kpersonquery_person_filter_fin__0": "rgInternal", @@ -95,7 +95,7 @@ def create_event( False, True, False, - PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS, + PersonsOnEventsMode.person_id_override_properties_on_events, { "event_names": [], "event_start_time": mock.ANY, @@ -111,7 +111,7 @@ def create_event( False, True, True, - PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS, + PersonsOnEventsMode.person_id_override_properties_on_events, { "event_end_time": mock.ANY, "event_names": [], @@ -130,7 +130,7 @@ def test_effect_of_poe_settings_on_query_generated( poe_v1: bool, poe_v2: bool, allow_denormalized_props: bool, - expected_poe_mode: PersonOnEventsMode, + expected_poe_mode: PersonsOnEventsMode, expected_query_params: Dict, unmaterialized_person_column_used: bool, materialized_event_column_used: bool, diff --git a/mypy-baseline.txt b/mypy-baseline.txt index 713cf17200a43..58a2acbea7c86 100644 --- a/mypy-baseline.txt +++ b/mypy-baseline.txt @@ -133,7 +133,6 @@ posthog/hogql_queries/legacy_compatibility/filter_to_query.py:0: error: Dict ent posthog/hogql_queries/legacy_compatibility/filter_to_query.py:0: error: Dict entry 0 has incompatible type "str": "LifecycleFilter"; expected "str": "TrendsFilter" [dict-item] posthog/hogql_queries/legacy_compatibility/filter_to_query.py:0: error: Dict entry 0 has incompatible type "str": "StickinessFilter"; expected "str": "TrendsFilter" [dict-item] posthog/hogql_queries/legacy_compatibility/feature_flag.py:0: error: Item "AnonymousUser" of "User | AnonymousUser" has no attribute "email" [union-attr] -posthog/hogql/modifiers.py:0: error: Incompatible types in assignment (expression has type "PersonOnEventsMode", variable has type "PersonsOnEventsMode | None") [assignment] posthog/api/utils.py:0: error: Incompatible types in assignment (expression has type "type[EventDefinition]", variable has type "type[EnterpriseEventDefinition]") [assignment] posthog/api/utils.py:0: error: Argument 1 to "UUID" has incompatible type "int | str"; expected "str | None" [arg-type] ee/billing/quota_limiting.py:0: error: List comprehension has incompatible type List[int]; expected List[str] [misc] @@ -276,16 +275,9 @@ posthog/hogql/printer.py:0: error: Name "args" already defined on line 0 [no-re posthog/hogql/printer.py:0: error: Name "args" already defined on line 0 [no-redef] posthog/hogql/printer.py:0: error: Argument 1 to "lookup_field_by_name" has incompatible type "SelectQueryType | None"; expected "SelectQueryType" [arg-type] posthog/hogql/printer.py:0: error: Item "TableType" of "TableType | TableAliasType" has no attribute "alias" [union-attr] -posthog/hogql/printer.py:0: error: Non-overlapping equality check (left operand type: "PersonsOnEventsMode | None", right operand type: "Literal[PersonOnEventsMode.DISABLED]") [comparison-overlap] -posthog/hogql/printer.py:0: error: Statement is unreachable [unreachable] posthog/hogql/printer.py:0: error: "FieldOrTable" has no attribute "name" [attr-defined] -posthog/hogql/printer.py:0: error: Non-overlapping equality check (left operand type: "PersonsOnEventsMode | None", right operand type: "Literal[PersonOnEventsMode.DISABLED]") [comparison-overlap] -posthog/hogql/printer.py:0: error: Statement is unreachable [unreachable] posthog/hogql/printer.py:0: error: "FieldOrTable" has no attribute "name" [attr-defined] posthog/hogql/printer.py:0: error: Argument 2 to "_get_materialized_column" of "_Printer" has incompatible type "str | int"; expected "str" [arg-type] -posthog/hogql/printer.py:0: error: Non-overlapping equality check (left operand type: "PersonsOnEventsMode | None", right operand type: "Literal[PersonOnEventsMode.DISABLED]") [comparison-overlap] -posthog/hogql/printer.py:0: error: Argument 2 to "_get_materialized_column" of "_Printer" has incompatible type "str | int"; expected "str" [arg-type] -posthog/hogql/printer.py:0: error: Statement is unreachable [unreachable] posthog/hogql/printer.py:0: error: Argument 1 to "_print_identifier" of "_Printer" has incompatible type "str | None"; expected "str" [arg-type] posthog/api/organization.py:0: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases [misc] posthog/api/organization.py:0: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases [misc] @@ -309,7 +301,6 @@ posthog/hogql/filters.py:0: note: PEP 484 prohibits implicit Optional. According posthog/hogql/filters.py:0: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase posthog/hogql/query.py:0: error: Incompatible types in assignment (expression has type "None", variable has type "str | SelectQuery | SelectUnionQuery") [assignment] posthog/hogql/query.py:0: error: Incompatible types in assignment (expression has type "Expr", variable has type "SelectQuery | SelectUnionQuery") [assignment] -posthog/hogql/query.py:0: error: Incompatible types in assignment (expression has type "Expr", variable has type "SelectQuery | SelectUnionQuery") [assignment] posthog/hogql/query.py:0: error: Argument 1 to "get_default_limit_for_context" has incompatible type "LimitContext | None"; expected "LimitContext" [arg-type] posthog/hogql/query.py:0: error: "SelectQuery" has no attribute "select_queries" [attr-defined] posthog/hogql/query.py:0: error: Subclass of "SelectQuery" and "SelectUnionQuery" cannot exist: would have incompatible method signatures [unreachable] @@ -330,12 +321,9 @@ posthog/hogql_queries/insights/trends/breakdown.py:0: error: Item "None" of "Bre posthog/hogql_queries/insights/trends/breakdown.py:0: error: Argument "breakdown_field" to "get_properties_chain" has incompatible type "str | float | list[str | float] | Any | None"; expected "str" [arg-type] posthog/hogql_queries/insights/trends/breakdown.py:0: error: Item "None" of "BreakdownFilter | None" has no attribute "breakdown_group_type_index" [union-attr] posthog/hogql_queries/hogql_query_runner.py:0: error: Statement is unreachable [unreachable] -posthog/hogql_queries/hogql_query_runner.py:0: error: Argument "placeholders" to "parse_select" has incompatible type "dict[str, Constant] | None"; expected "dict[str, Expr] | None" [arg-type] -posthog/hogql_queries/hogql_query_runner.py:0: error: Incompatible types in assignment (expression has type "Expr", variable has type "SelectQuery | SelectUnionQuery") [assignment] posthog/hogql_queries/hogql_query_runner.py:0: error: Incompatible return value type (got "SelectQuery | SelectUnionQuery", expected "SelectQuery") [return-value] posthog/hogql_queries/events_query_runner.py:0: error: Statement is unreachable [unreachable] posthog/hogql/metadata.py:0: error: Argument "metadata_source" to "translate_hogql" has incompatible type "SelectQuery | SelectUnionQuery"; expected "SelectQuery | None" [arg-type] -posthog/hogql/metadata.py:0: error: Incompatible types in assignment (expression has type "Expr", variable has type "SelectQuery | SelectUnionQuery") [assignment] posthog/queries/breakdown_props.py:0: error: Argument 1 to "translate_hogql" has incompatible type "str | int"; expected "str" [arg-type] posthog/queries/funnels/base.py:0: error: "HogQLContext" has no attribute "person_on_events_mode" [attr-defined] posthog/queries/funnels/base.py:0: error: Argument 1 to "translate_hogql" has incompatible type "str | int"; expected "str" [arg-type] @@ -422,8 +410,6 @@ posthog/session_recordings/queries/session_recording_list_from_replay_summary.py posthog/session_recordings/queries/session_recording_list_from_replay_summary.py:0: note: If the method is meant to be abstract, use @abc.abstractmethod posthog/session_recordings/queries/session_recording_list_from_replay_summary.py:0: error: Missing return statement [empty-body] posthog/session_recordings/queries/session_recording_list_from_replay_summary.py:0: note: If the method is meant to be abstract, use @abc.abstractmethod -posthog/session_recordings/queries/session_recording_list_from_replay_summary.py:0: error: Incompatible types in assignment (expression has type "PersonOnEventsMode", variable has type "PersonsOnEventsMode | None") [assignment] -posthog/session_recordings/queries/session_recording_list_from_replay_summary.py:0: error: Incompatible types in assignment (expression has type "PersonOnEventsMode", variable has type "PersonsOnEventsMode | None") [assignment] posthog/hogql_queries/test/test_query_runner.py:0: error: Variable "TestQueryRunner" is not valid as a type [valid-type] posthog/hogql_queries/test/test_query_runner.py:0: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases posthog/hogql_queries/test/test_query_runner.py:0: error: Invalid base class "TestQueryRunner" [misc] diff --git a/posthog/hogql/filters.py b/posthog/hogql/filters.py index 78bef13675f70..dcec66efad6e0 100644 --- a/posthog/hogql/filters.py +++ b/posthog/hogql/filters.py @@ -1,4 +1,4 @@ -from typing import List, Optional +from typing import List, Optional, TypeVar from dateutil.parser import isoparse @@ -12,7 +12,10 @@ from posthog.utils import relative_date_parse -def replace_filters(node: ast.Expr, filters: Optional[HogQLFilters], team: Team) -> ast.Expr: +T = TypeVar("T", bound=ast.Expr) + + +def replace_filters(node: T, filters: Optional[HogQLFilters], team: Team) -> T: return ReplaceFilters(filters, team).visit(node) diff --git a/posthog/hogql/modifiers.py b/posthog/hogql/modifiers.py index 3c6fa11a9fc3b..c14e952dcb3c0 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,7 @@ 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 + modifiers.personsOnEventsMode = team.person_on_events_mode or PersonsOnEventsMode.disabled if modifiers.personsArgMaxVersion is None: modifiers.personsArgMaxVersion = PersonsArgMaxVersion.auto diff --git a/posthog/hogql/printer.py b/posthog/hogql/printer.py index 3b6ad33dd876d..3f5be7cc42b83 100644 --- a/posthog/hogql/printer.py +++ b/posthog/hogql/printer.py @@ -41,8 +41,7 @@ from posthog.models.team.team import WeekStartDay from posthog.models.team import Team from posthog.models.utils import UUIDT -from posthog.schema import HogQLQueryModifiers, InCohortVia, MaterializationMode -from posthog.utils import PersonOnEventsMode +from posthog.schema import HogQLQueryModifiers, InCohortVia, MaterializationMode, PersonsOnEventsMode def team_id_guard_for_table(table_type: Union[ast.TableType, ast.TableAliasType], context: HogQLContext) -> ast.Expr: @@ -954,7 +953,7 @@ def visit_field_type(self, type: ast.FieldType): and type.name == "properties" and type.table_type.field == "poe" ): - if self.context.modifiers.personsOnEventsMode != PersonOnEventsMode.DISABLED: + if self.context.modifiers.personsOnEventsMode != PersonsOnEventsMode.disabled: field_sql = "person_properties" else: field_sql = "person_props" @@ -978,7 +977,7 @@ def visit_field_type(self, type: ast.FieldType): # :KLUDGE: Legacy person properties handling. Only used within non-HogQL queries, such as insights. if self.context.within_non_hogql_query and field_sql == "events__pdi__person.properties": - if self.context.modifiers.personsOnEventsMode != PersonOnEventsMode.DISABLED: + if self.context.modifiers.personsOnEventsMode != PersonsOnEventsMode.disabled: field_sql = "person_properties" else: field_sql = "person_props" @@ -1028,10 +1027,12 @@ def visit_property_type(self, type: ast.PropertyType): or (isinstance(table, ast.VirtualTableType) and table.field == "poe") ): # :KLUDGE: Legacy person properties handling. Only used within non-HogQL queries, such as insights. - if self.context.modifiers.personsOnEventsMode != PersonOnEventsMode.DISABLED: - materialized_column = self._get_materialized_column("events", type.chain[0], "person_properties") + if self.context.modifiers.personsOnEventsMode != PersonsOnEventsMode.disabled: + materialized_column = self._get_materialized_column( + "events", str(type.chain[0]), "person_properties" + ) else: - materialized_column = self._get_materialized_column("person", type.chain[0], "properties") + materialized_column = self._get_materialized_column("person", str(type.chain[0]), "properties") if materialized_column: materialized_property_sql = self._print_identifier(materialized_column) diff --git a/posthog/hogql/test/test_printer.py b/posthog/hogql/test/test_printer.py index a4d5337071b3d..1a8a2130c5245 100644 --- a/posthog/hogql/test/test_printer.py +++ b/posthog/hogql/test/test_printer.py @@ -14,9 +14,8 @@ from posthog.hogql.printer import print_ast, to_printed_hogql from posthog.models import PropertyDefinition from posthog.models.team.team import WeekStartDay -from posthog.schema import HogQLQueryModifiers, PersonsArgMaxVersion +from posthog.schema import HogQLQueryModifiers, PersonsArgMaxVersion, PersonsOnEventsMode from posthog.test.base import BaseTest -from posthog.utils import PersonOnEventsMode class TestPrinter(BaseTest): @@ -140,7 +139,7 @@ def test_fields_and_properties(self): context = HogQLContext( team_id=self.team.pk, within_non_hogql_query=True, - modifiers=HogQLQueryModifiers(personsOnEventsMode=PersonOnEventsMode.DISABLED), + modifiers=HogQLQueryModifiers(personsOnEventsMode=PersonsOnEventsMode.disabled), ) self.assertEqual( self._expr("person.properties.bla", context), @@ -157,7 +156,7 @@ def test_fields_and_properties(self): team_id=self.team.pk, within_non_hogql_query=True, modifiers=HogQLQueryModifiers( - personsOnEventsMode=PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS + personsOnEventsMode=PersonsOnEventsMode.person_id_no_override_properties_on_events ), ) self.assertEqual( diff --git a/posthog/hogql/transforms/property_types.py b/posthog/hogql/transforms/property_types.py index 1f0b34ae3cec3..cc5451bf6bc3a 100644 --- a/posthog/hogql/transforms/property_types.py +++ b/posthog/hogql/transforms/property_types.py @@ -6,7 +6,7 @@ from posthog.hogql.escape_sql import escape_hogql_identifier from posthog.hogql.visitor import CloningVisitor, TraversingVisitor from posthog.models.property import PropertyName, TableColumn -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode def resolve_property_types(node: ast.Expr, context: HogQLContext) -> ast.Expr: @@ -224,10 +224,10 @@ def _add_property_notice( ): property_name = str(node.chain[-1]) if property_type == "person": - if self.context.modifiers.personsOnEventsMode != PersonOnEventsMode.DISABLED: # type: ignore[comparison-overlap] + if self.context.modifiers.personsOnEventsMode != PersonsOnEventsMode.disabled: materialized_column = self._get_materialized_column("events", property_name, "person_properties") else: - materialized_column = self._get_materialized_column("person", property_name, "properties") # type: ignore[unreachable] + materialized_column = self._get_materialized_column("person", property_name, "properties") elif property_type == "group": name_parts = property_name.split("_") name_parts.pop(0) diff --git a/posthog/hogql_queries/hogql_query_runner.py b/posthog/hogql_queries/hogql_query_runner.py index 7f30ae435803c..46b4c105a4336 100644 --- a/posthog/hogql_queries/hogql_query_runner.py +++ b/posthog/hogql_queries/hogql_query_runner.py @@ -1,5 +1,5 @@ from datetime import timedelta -from typing import Callable, cast +from typing import Callable, Dict, Optional, cast from posthog.clickhouse.client.connection import Workload from posthog.hogql import ast @@ -26,7 +26,7 @@ class HogQLQueryRunner(QueryRunner): def to_query(self) -> ast.SelectQuery: if self.timings is None: self.timings = HogQLTimings() - values = ( + values: Optional[Dict[str, ast.Expr]] = ( {key: ast.Constant(value=value) for key, value in self.query.values.items()} if self.query.values else None ) with self.timings.measure("parse_select"): diff --git a/posthog/models/team/team.py b/posthog/models/team/team.py index c199c6bcc1d56..19cb99cf67762 100644 --- a/posthog/models/team/team.py +++ b/posthog/models/team/team.py @@ -33,10 +33,10 @@ sane_repr, ) from posthog.settings.utils import get_list -from posthog.utils import GenericEmails, PersonOnEventsMode +from posthog.utils import GenericEmails from .team_caching import get_team_in_cache, set_team_in_cache -from ...schema import PathCleaningFilter +from ...schema import PathCleaningFilter, PersonsOnEventsMode if TYPE_CHECKING: from posthog.models.user import User @@ -289,33 +289,33 @@ def aggregate_users_by_distinct_id(self) -> bool: objects: TeamManager = TeamManager() @property - def person_on_events_mode(self) -> PersonOnEventsMode: + def person_on_events_mode(self) -> PersonsOnEventsMode: if self._person_on_events_person_id_override_properties_on_events: - tag_queries(person_on_events_mode=PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS) - return PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS + tag_queries(person_on_events_mode=PersonsOnEventsMode.person_id_override_properties_on_events) + return PersonsOnEventsMode.person_id_override_properties_on_events if self._person_on_events_person_id_no_override_properties_on_events: # also tag person_on_events_enabled for legacy compatibility tag_queries( person_on_events_enabled=True, - person_on_events_mode=PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS, + person_on_events_mode=PersonsOnEventsMode.person_id_no_override_properties_on_events, ) - return PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS + return PersonsOnEventsMode.person_id_no_override_properties_on_events if self._person_on_events_person_id_override_properties_joined: tag_queries( person_on_events_enabled=True, - person_on_events_mode=PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_JOINED, + person_on_events_mode=PersonsOnEventsMode.person_id_override_properties_joined, ) - return PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_JOINED + return PersonsOnEventsMode.person_id_override_properties_joined - return PersonOnEventsMode.DISABLED + return PersonsOnEventsMode.disabled # KLUDGE: DO NOT REFERENCE IN THE BACKEND! # Keeping this property for now only to be used by the frontend in certain cases @property def person_on_events_querying_enabled(self) -> bool: - return self.person_on_events_mode != PersonOnEventsMode.DISABLED + return self.person_on_events_mode != PersonsOnEventsMode.disabled @property def _person_on_events_person_id_no_override_properties_on_events(self) -> bool: diff --git a/posthog/queries/breakdown_props.py b/posthog/queries/breakdown_props.py index 64a550edf543d..397ee061332e6 100644 --- a/posthog/queries/breakdown_props.py +++ b/posthog/queries/breakdown_props.py @@ -30,13 +30,13 @@ from posthog.queries.person_on_events_v2_sql import PERSON_OVERRIDES_JOIN_SQL from posthog.queries.person_query import PersonQuery from posthog.queries.query_date_range import QueryDateRange +from posthog.schema import PersonsOnEventsMode from posthog.session_recordings.queries.session_query import SessionQuery from posthog.queries.trends.sql import ( HISTOGRAM_ELEMENTS_ARRAY_OF_KEY_SQL, TOP_ELEMENTS_ARRAY_OF_KEY_SQL, ) from posthog.queries.util import PersonPropertiesMode -from posthog.utils import PersonOnEventsMode ALL_USERS_COHORT_ID = 0 @@ -84,7 +84,7 @@ def get_breakdown_prop_values( sessions_join_params: Dict = {} null_person_filter = ( - f"AND notEmpty(e.person_id)" if team.person_on_events_mode != PersonOnEventsMode.DISABLED else "" + f"AND notEmpty(e.person_id)" if team.person_on_events_mode != PersonsOnEventsMode.disabled else "" ) if person_properties_mode == PersonPropertiesMode.DIRECT_ON_EVENTS: diff --git a/posthog/queries/event_query/event_query.py b/posthog/queries/event_query/event_query.py index aa292e7ee44e4..bcd7002e66f47 100644 --- a/posthog/queries/event_query/event_query.py +++ b/posthog/queries/event_query/event_query.py @@ -18,9 +18,9 @@ from posthog.queries.person_distinct_id_query import get_team_distinct_ids_query from posthog.queries.person_query import PersonQuery from posthog.queries.query_date_range import QueryDateRange +from posthog.schema import PersonsOnEventsMode from posthog.session_recordings.queries.session_query import SessionQuery from posthog.queries.util import PersonPropertiesMode -from posthog.utils import PersonOnEventsMode from posthog.queries.person_on_events_v2_sql import PERSON_OVERRIDES_JOIN_SQL @@ -64,7 +64,7 @@ def __init__( extra_event_properties: List[PropertyName] = [], extra_person_fields: List[ColumnName] = [], override_aggregate_users_by_distinct_id: Optional[bool] = None, - person_on_events_mode: PersonOnEventsMode = PersonOnEventsMode.DISABLED, + person_on_events_mode: PersonsOnEventsMode = PersonsOnEventsMode.disabled, **kwargs, ) -> None: self._filter = filter @@ -120,9 +120,9 @@ def _determine_should_join_distinct_ids(self) -> None: pass def _get_person_id_alias(self, person_on_events_mode) -> str: - if person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS: + if person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events: return f"if(notEmpty({self.PERSON_ID_OVERRIDES_TABLE_ALIAS}.person_id), {self.PERSON_ID_OVERRIDES_TABLE_ALIAS}.person_id, {self.EVENT_TABLE_ALIAS}.person_id)" - elif person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + elif person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: return f"{self.EVENT_TABLE_ALIAS}.person_id" return f"{self.DISTINCT_ID_TABLE_ALIAS}.person_id" @@ -131,7 +131,7 @@ def _get_person_ids_query(self, *, relevant_events_conditions: str = "") -> str: if not self._should_join_distinct_ids: return "" - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS: + if self._person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events: return PERSON_OVERRIDES_JOIN_SQL.format( person_overrides_table_alias=self.PERSON_ID_OVERRIDES_TABLE_ALIAS, event_table_alias=self.EVENT_TABLE_ALIAS, diff --git a/posthog/queries/foss_cohort_query.py b/posthog/queries/foss_cohort_query.py index 03ddf348e181a..91d16ec3ec5a4 100644 --- a/posthog/queries/foss_cohort_query.py +++ b/posthog/queries/foss_cohort_query.py @@ -23,7 +23,8 @@ from posthog.models.property.util import prop_filter_json_extract, parse_prop_grouped_clauses from posthog.queries.event_query import EventQuery from posthog.queries.util import PersonPropertiesMode -from posthog.utils import PersonOnEventsMode, relative_date_parse +from posthog.schema import PersonsOnEventsMode +from posthog.utils import relative_date_parse Relative_Date = Tuple[int, OperatorInterval] Event = Tuple[str, Union[str, int]] @@ -299,7 +300,7 @@ def _build_sources(self, subq: List[Tuple[str, str]]) -> Tuple[str, str]: fields = f"{subq_alias}.person_id" elif prev_alias: # can't join without a previous alias if subq_alias == self.PERSON_TABLE_ALIAS and self.should_pushdown_persons: - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + if self._person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: # when using person-on-events, instead of inner join, we filter inside # the event query itself continue @@ -330,11 +331,11 @@ def _get_behavior_subquery(self) -> Tuple[str, Dict[str, Any], str]: query, params = "", {} if self._should_join_behavioral_query: _fields = [ - f"{self.DISTINCT_ID_TABLE_ALIAS if self._person_on_events_mode == PersonOnEventsMode.DISABLED else self.EVENT_TABLE_ALIAS}.person_id AS person_id" + f"{self.DISTINCT_ID_TABLE_ALIAS if self._person_on_events_mode == PersonsOnEventsMode.disabled else self.EVENT_TABLE_ALIAS}.person_id AS person_id" ] _fields.extend(self._fields) - if self.should_pushdown_persons and self._person_on_events_mode != PersonOnEventsMode.DISABLED: + if self.should_pushdown_persons and self._person_on_events_mode != PersonsOnEventsMode.disabled: person_prop_query, person_prop_params = self._get_prop_groups( self._inner_property_groups, person_properties_mode=PersonPropertiesMode.DIRECT_ON_EVENTS, @@ -550,7 +551,7 @@ def get_performed_event_multiple(self, prop: Property, prepend: str, idx: int) - def _determine_should_join_distinct_ids(self) -> None: self._should_join_distinct_ids = ( - self._person_on_events_mode != PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS + self._person_on_events_mode != PersonsOnEventsMode.person_id_no_override_properties_on_events ) def _determine_should_join_persons(self) -> None: diff --git a/posthog/queries/funnels/base.py b/posthog/queries/funnels/base.py index 244ede082b7ac..a96ba9b9f7f7c 100644 --- a/posthog/queries/funnels/base.py +++ b/posthog/queries/funnels/base.py @@ -33,7 +33,8 @@ from posthog.queries.funnels.funnel_event_query import FunnelEventQuery from posthog.queries.insight import insight_sync_execute from posthog.queries.util import correct_result_for_sampling, get_person_properties_mode -from posthog.utils import PersonOnEventsMode, relative_date_parse, generate_short_id +from posthog.schema import PersonsOnEventsMode +from posthog.utils import relative_date_parse, generate_short_id class ClickhouseFunnelBase(ABC): @@ -727,7 +728,7 @@ def _get_breakdown_select_prop(self) -> Tuple[str, Dict[str, Any]]: self.params.update({"breakdown": self._filter.breakdown}) if self._filter.breakdown_type == "person": - if self._team.person_on_events_mode != PersonOnEventsMode.DISABLED: + if self._team.person_on_events_mode != PersonsOnEventsMode.disabled: basic_prop_selector, basic_prop_params = get_single_or_multi_property_string_expr( self._filter.breakdown, table="events", @@ -757,7 +758,7 @@ def _get_breakdown_select_prop(self) -> Tuple[str, Dict[str, Any]]: # :TRICKY: We only support string breakdown for group properties assert isinstance(self._filter.breakdown, str) - if self._team.person_on_events_mode != PersonOnEventsMode.DISABLED and groups_on_events_querying_enabled(): + if self._team.person_on_events_mode != PersonsOnEventsMode.disabled and groups_on_events_querying_enabled(): properties_field = f"group{self._filter.breakdown_group_type_index}_properties" expression, _ = get_property_string_expr( table="events", diff --git a/posthog/queries/funnels/funnel_event_query.py b/posthog/queries/funnels/funnel_event_query.py index d2393f77b5d21..2c8ad72524f70 100644 --- a/posthog/queries/funnels/funnel_event_query.py +++ b/posthog/queries/funnels/funnel_event_query.py @@ -6,7 +6,7 @@ from posthog.models.group.util import get_aggregation_target_field from posthog.queries.event_query import EventQuery from posthog.queries.util import get_person_properties_mode -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class FunnelEventQuery(EventQuery): @@ -49,7 +49,7 @@ def get_query( _fields += [f"{self.EVENT_TABLE_ALIAS}.{field} AS {field}" for field in self._extra_fields] - if self._person_on_events_mode != PersonOnEventsMode.DISABLED: + if self._person_on_events_mode != PersonsOnEventsMode.disabled: _fields += [f"{self._person_id_alias} as person_id"] _fields.extend( @@ -95,7 +95,7 @@ def get_query( null_person_filter = ( f"AND notEmpty({self.EVENT_TABLE_ALIAS}.person_id)" - if self._person_on_events_mode != PersonOnEventsMode.DISABLED + if self._person_on_events_mode != PersonsOnEventsMode.disabled else "" ) @@ -131,9 +131,9 @@ def _determine_should_join_distinct_ids(self) -> None: ) is_using_cohort_propertes = self._column_optimizer.is_using_cohort_propertes - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS: + if self._person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events: self._should_join_distinct_ids = True - elif self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS or ( + elif self._person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events or ( non_person_id_aggregation and not is_using_cohort_propertes ): self._should_join_distinct_ids = False @@ -142,7 +142,7 @@ def _determine_should_join_distinct_ids(self) -> None: def _determine_should_join_persons(self) -> None: EventQuery._determine_should_join_persons(self) - if self._person_on_events_mode != PersonOnEventsMode.DISABLED: + if self._person_on_events_mode != PersonsOnEventsMode.disabled: self._should_join_persons = False def _get_entity_query(self, entities=None, entity_name="events") -> Tuple[str, Dict[str, Any]]: diff --git a/posthog/queries/groups_join_query/groups_join_query.py b/posthog/queries/groups_join_query/groups_join_query.py index fb8b46ae591b9..2cc62849cacc3 100644 --- a/posthog/queries/groups_join_query/groups_join_query.py +++ b/posthog/queries/groups_join_query/groups_join_query.py @@ -5,7 +5,7 @@ from posthog.models.filters.retention_filter import RetentionFilter from posthog.models.filters.stickiness_filter import StickinessFilter from posthog.queries.column_optimizer.column_optimizer import ColumnOptimizer -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class GroupsJoinQuery: @@ -23,7 +23,7 @@ def __init__( team_id: int, column_optimizer: Optional[ColumnOptimizer] = None, join_key: Optional[str] = None, - person_on_events_mode: PersonOnEventsMode = PersonOnEventsMode.DISABLED, + person_on_events_mode: PersonsOnEventsMode = PersonsOnEventsMode.disabled, ) -> None: self._filter = filter self._team_id = team_id diff --git a/posthog/queries/paths/paths_event_query.py b/posthog/queries/paths/paths_event_query.py index 5c222558973a2..61b032aa663ec 100644 --- a/posthog/queries/paths/paths_event_query.py +++ b/posthog/queries/paths/paths_event_query.py @@ -14,7 +14,7 @@ from posthog.models.team import Team from posthog.queries.event_query import EventQuery from posthog.queries.util import get_person_properties_mode -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class PathEventQuery(EventQuery): @@ -116,7 +116,7 @@ def get_query(self) -> Tuple[str, Dict[str, Any]]: null_person_filter = ( f"AND notEmpty({self.EVENT_TABLE_ALIAS}.person_id)" - if self._person_on_events_mode != PersonOnEventsMode.DISABLED + if self._person_on_events_mode != PersonsOnEventsMode.disabled else "" ) @@ -141,14 +141,14 @@ def get_query(self) -> Tuple[str, Dict[str, Any]]: return query, self.params def _determine_should_join_distinct_ids(self) -> None: - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + if self._person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: self._should_join_distinct_ids = False else: self._should_join_distinct_ids = True def _determine_should_join_persons(self) -> None: EventQuery._determine_should_join_persons(self) - if self._person_on_events_mode != PersonOnEventsMode.DISABLED: + if self._person_on_events_mode != PersonsOnEventsMode.disabled: self._should_join_persons = False def _get_grouping_fields(self) -> Tuple[List[str], Dict[str, Any]]: diff --git a/posthog/queries/retention/retention.py b/posthog/queries/retention/retention.py index 5536a02940b9e..8f8b0d89254bf 100644 --- a/posthog/queries/retention/retention.py +++ b/posthog/queries/retention/retention.py @@ -14,7 +14,7 @@ from posthog.queries.retention.sql import RETENTION_BREAKDOWN_SQL from posthog.queries.retention.types import BreakdownValues, CohortKey from posthog.queries.util import correct_result_for_sampling -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class Retention: @@ -166,7 +166,7 @@ def build_returning_event_query( filter: RetentionFilter, team: Team, aggregate_users_by_distinct_id: Optional[bool] = None, - person_on_events_mode: PersonOnEventsMode = PersonOnEventsMode.DISABLED, + person_on_events_mode: PersonsOnEventsMode = PersonsOnEventsMode.disabled, retention_events_query=RetentionEventsQuery, ) -> Tuple[str, Dict[str, Any]]: returning_event_query_templated, returning_event_params = retention_events_query( @@ -184,7 +184,7 @@ def build_target_event_query( filter: RetentionFilter, team: Team, aggregate_users_by_distinct_id: Optional[bool] = None, - person_on_events_mode: PersonOnEventsMode = PersonOnEventsMode.DISABLED, + person_on_events_mode: PersonsOnEventsMode = PersonsOnEventsMode.disabled, retention_events_query=RetentionEventsQuery, ) -> Tuple[str, Dict[str, Any]]: target_event_query_templated, target_event_params = retention_events_query( diff --git a/posthog/queries/retention/retention_events_query.py b/posthog/queries/retention/retention_events_query.py index 871d9dbb3e033..e84e4bc1e91cc 100644 --- a/posthog/queries/retention/retention_events_query.py +++ b/posthog/queries/retention/retention_events_query.py @@ -14,7 +14,7 @@ from posthog.models.team import Team from posthog.queries.event_query import EventQuery from posthog.queries.util import get_person_properties_mode, get_start_of_interval_sql -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class RetentionEventsQuery(EventQuery): @@ -27,7 +27,7 @@ def __init__( event_query_type: RetentionQueryType, team: Team, aggregate_users_by_distinct_id: Optional[bool] = None, - person_on_events_mode: PersonOnEventsMode = PersonOnEventsMode.DISABLED, + person_on_events_mode: PersonsOnEventsMode = PersonsOnEventsMode.disabled, ): self._event_query_type = event_query_type super().__init__( @@ -56,14 +56,14 @@ def get_query(self) -> Tuple[str, Dict[str, Any]]: materalised_table_column = "properties" if breakdown_type == "person": - table = "person" if self._person_on_events_mode == PersonOnEventsMode.DISABLED else "events" + table = "person" if self._person_on_events_mode == PersonsOnEventsMode.disabled else "events" column = ( "person_props" - if self._person_on_events_mode == PersonOnEventsMode.DISABLED + if self._person_on_events_mode == PersonsOnEventsMode.disabled else "person_properties" ) materalised_table_column = ( - "properties" if self._person_on_events_mode == PersonOnEventsMode.DISABLED else "person_properties" + "properties" if self._person_on_events_mode == PersonsOnEventsMode.disabled else "person_properties" ) breakdown_values_expression, breakdown_values_params = get_single_or_multi_property_string_expr( @@ -149,7 +149,7 @@ def get_query(self) -> Tuple[str, Dict[str, Any]]: null_person_filter = ( f"AND notEmpty({self.EVENT_TABLE_ALIAS}.person_id)" - if self._person_on_events_mode != PersonOnEventsMode.DISABLED + if self._person_on_events_mode != PersonsOnEventsMode.disabled else "" ) @@ -197,7 +197,7 @@ def _determine_should_join_distinct_ids(self) -> None: self._filter.aggregation_group_type_index is not None or self._aggregate_users_by_distinct_id ) is_using_cohort_propertes = self._column_optimizer.is_using_cohort_propertes - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS or ( + if self._person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events or ( non_person_id_aggregation and not is_using_cohort_propertes ): self._should_join_distinct_ids = False @@ -206,7 +206,7 @@ def _determine_should_join_distinct_ids(self) -> None: def _determine_should_join_persons(self) -> None: EventQuery._determine_should_join_persons(self) - if self._person_on_events_mode != PersonOnEventsMode.DISABLED: + if self._person_on_events_mode != PersonsOnEventsMode.disabled: self._should_join_persons = False def _get_entity_query(self, entity: Entity): diff --git a/posthog/queries/stickiness/stickiness_event_query.py b/posthog/queries/stickiness/stickiness_event_query.py index ce76b2d17ce5c..25d68b1d6bfdf 100644 --- a/posthog/queries/stickiness/stickiness_event_query.py +++ b/posthog/queries/stickiness/stickiness_event_query.py @@ -8,7 +8,7 @@ from posthog.queries.event_query import EventQuery from posthog.queries.person_query import PersonQuery from posthog.queries.util import get_person_properties_mode, get_start_of_interval_sql -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class StickinessEventsQuery(EventQuery): @@ -43,7 +43,7 @@ def get_query(self) -> Tuple[str, Dict[str, Any]]: null_person_filter = ( f"AND notEmpty({self.EVENT_TABLE_ALIAS}.person_id)" - if self._person_on_events_mode != PersonOnEventsMode.DISABLED + if self._person_on_events_mode != PersonsOnEventsMode.disabled else "" ) @@ -82,14 +82,14 @@ def _person_query(self): ) def _determine_should_join_distinct_ids(self) -> None: - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + if self._person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: self._should_join_distinct_ids = False else: self._should_join_distinct_ids = True def _determine_should_join_persons(self) -> None: EventQuery._determine_should_join_persons(self) - if self._person_on_events_mode != PersonOnEventsMode.DISABLED: + if self._person_on_events_mode != PersonsOnEventsMode.disabled: self._should_join_persons = False def aggregation_target(self): diff --git a/posthog/queries/trends/breakdown.py b/posthog/queries/trends/breakdown.py index de8665a549610..444f045384a14 100644 --- a/posthog/queries/trends/breakdown.py +++ b/posthog/queries/trends/breakdown.py @@ -43,6 +43,7 @@ from posthog.queries.person_distinct_id_query import get_team_distinct_ids_query from posthog.queries.person_query import PersonQuery from posthog.queries.query_date_range import TIME_IN_SECONDS, QueryDateRange +from posthog.schema import PersonsOnEventsMode from posthog.session_recordings.queries.session_query import SessionQuery from posthog.queries.trends.sql import ( BREAKDOWN_ACTIVE_USER_AGGREGATE_SQL, @@ -76,11 +77,7 @@ get_person_properties_mode, get_start_of_interval_sql, ) -from posthog.utils import ( - PersonOnEventsMode, - encode_get_request_params, - generate_short_id, -) +from posthog.utils import encode_get_request_params, generate_short_id from posthog.queries.person_on_events_v2_sql import PERSON_OVERRIDES_JOIN_SQL BREAKDOWN_OTHER_STRING_LABEL = "$$_posthog_breakdown_other_$$" @@ -100,7 +97,7 @@ def __init__( filter: Filter, team: Team, column_optimizer: Optional[ColumnOptimizer] = None, - person_on_events_mode: PersonOnEventsMode = PersonOnEventsMode.DISABLED, + person_on_events_mode: PersonsOnEventsMode = PersonsOnEventsMode.disabled, add_person_urls: bool = False, ): self.entity = entity @@ -111,9 +108,9 @@ def __init__( self.column_optimizer = column_optimizer or ColumnOptimizer(self.filter, self.team_id) self.add_person_urls = add_person_urls self.person_on_events_mode = person_on_events_mode - if person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS: + if person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events: self._person_id_alias = f"if(notEmpty({self.PERSON_ID_OVERRIDES_TABLE_ALIAS}.person_id), {self.PERSON_ID_OVERRIDES_TABLE_ALIAS}.person_id, {self.EVENT_TABLE_ALIAS}.person_id)" - elif person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + elif person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: self._person_id_alias = f"{self.EVENT_TABLE_ALIAS}.person_id" else: self._person_id_alias = f"{self.DISTINCT_ID_TABLE_ALIAS}.person_id" @@ -131,7 +128,7 @@ def _props_to_filter(self) -> Tuple[str, Dict]: ) target_properties: Optional[PropertyGroup] = props_to_filter - if self.person_on_events_mode == PersonOnEventsMode.DISABLED: + if self.person_on_events_mode == PersonsOnEventsMode.disabled: target_properties = self.column_optimizer.property_optimizer.parse_property_groups(props_to_filter).outer return parse_prop_grouped_clauses( @@ -163,7 +160,7 @@ def get_query(self) -> Tuple[str, Dict, Callable]: filter=self.filter, event_table_alias=self.EVENT_TABLE_ALIAS, person_id_alias=f"person_id" - if self.person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS + if self.person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events else self._person_id_alias, ) @@ -200,7 +197,7 @@ def get_query(self) -> Tuple[str, Dict, Callable]: else "", "filters": prop_filters, "null_person_filter": f"AND notEmpty(e.person_id)" - if self.person_on_events_mode != PersonOnEventsMode.DISABLED + if self.person_on_events_mode != PersonsOnEventsMode.disabled else "", } @@ -522,7 +519,7 @@ def _get_breakdown_value(self, breakdown: str) -> str: raise ValidationError(f'Invalid breakdown "{breakdown}" for breakdown type "session"') elif ( - self.person_on_events_mode != PersonOnEventsMode.DISABLED + self.person_on_events_mode != PersonsOnEventsMode.disabled and self.filter.breakdown_type == "group" and groups_on_events_querying_enabled() ): @@ -534,7 +531,7 @@ def _get_breakdown_value(self, breakdown: str) -> str: properties_field, materialised_table_column=properties_field, ) - elif self.person_on_events_mode != PersonOnEventsMode.DISABLED and self.filter.breakdown_type != "group": + elif self.person_on_events_mode != PersonsOnEventsMode.disabled and self.filter.breakdown_type != "group": if self.filter.breakdown_type == "person": breakdown_value, _ = get_property_string_expr( "events", @@ -748,10 +745,10 @@ def _determine_breakdown_label( return str(value) or BREAKDOWN_NULL_DISPLAY def _person_join_condition(self) -> Tuple[str, Dict]: - if self.person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + if self.person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: return "", {} - if self.person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS: + if self.person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events: return ( PERSON_OVERRIDES_JOIN_SQL.format( person_overrides_table_alias=self.PERSON_ID_OVERRIDES_TABLE_ALIAS, diff --git a/posthog/queries/trends/lifecycle.py b/posthog/queries/trends/lifecycle.py index 6397439d8922b..2629672879e7a 100644 --- a/posthog/queries/trends/lifecycle.py +++ b/posthog/queries/trends/lifecycle.py @@ -13,11 +13,8 @@ from posthog.queries.trends.sql import LIFECYCLE_EVENTS_QUERY, LIFECYCLE_SQL from posthog.queries.trends.util import parse_response from posthog.queries.util import get_person_properties_mode -from posthog.utils import ( - PersonOnEventsMode, - encode_get_request_params, - generate_short_id, -) +from posthog.schema import PersonsOnEventsMode +from posthog.utils import encode_get_request_params, generate_short_id # Lifecycle takes an event/action, time range, interval and for every period, splits the users who did the action into 4: # @@ -128,12 +125,12 @@ def get_query(self): self.params.update(entity_prop_params) created_at_clause = ( - "person.created_at" if self._person_on_events_mode == PersonOnEventsMode.DISABLED else "person_created_at" + "person.created_at" if self._person_on_events_mode == PersonsOnEventsMode.disabled else "person_created_at" ) null_person_filter = ( "" - if self._person_on_events_mode == PersonOnEventsMode.DISABLED + if self._person_on_events_mode == PersonsOnEventsMode.disabled else f"AND notEmpty({self.EVENT_TABLE_ALIAS}.person_id)" ) @@ -189,8 +186,8 @@ def _get_date_filter(self): def _determine_should_join_distinct_ids(self) -> None: self._should_join_distinct_ids = ( - self._person_on_events_mode != PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS + self._person_on_events_mode != PersonsOnEventsMode.person_id_no_override_properties_on_events ) def _determine_should_join_persons(self) -> None: - self._should_join_persons = self._person_on_events_mode == PersonOnEventsMode.DISABLED + self._should_join_persons = self._person_on_events_mode == PersonsOnEventsMode.disabled diff --git a/posthog/queries/trends/total_volume.py b/posthog/queries/trends/total_volume.py index 9c7977ca02592..e36f6d2de7313 100644 --- a/posthog/queries/trends/total_volume.py +++ b/posthog/queries/trends/total_volume.py @@ -38,16 +38,9 @@ parse_response, process_math, ) -from posthog.queries.util import ( - TIME_IN_SECONDS, - get_interval_func_ch, - get_start_of_interval_sql, -) -from posthog.utils import ( - PersonOnEventsMode, - encode_get_request_params, - generate_short_id, -) +from posthog.queries.util import TIME_IN_SECONDS, get_interval_func_ch, get_start_of_interval_sql +from posthog.schema import PersonsOnEventsMode +from posthog.utils import encode_get_request_params, generate_short_id class TrendsTotalVolume: @@ -59,9 +52,9 @@ def _total_volume_query(self, entity: Entity, filter: Filter, team: Team) -> Tup interval_func = get_interval_func_ch(filter.interval) person_id_alias = f"{self.DISTINCT_ID_TABLE_ALIAS}.person_id" - if team.person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS: + if team.person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events: person_id_alias = f"if(notEmpty({self.PERSON_ID_OVERRIDES_TABLE_ALIAS}.person_id), {self.PERSON_ID_OVERRIDES_TABLE_ALIAS}.person_id, {self.EVENT_TABLE_ALIAS}.person_id)" - elif team.person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + elif team.person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: person_id_alias = f"{self.EVENT_TABLE_ALIAS}.person_id" aggregate_operation, join_condition, math_params = process_math( diff --git a/posthog/queries/trends/trends_actors.py b/posthog/queries/trends/trends_actors.py index 1648e7575e7b2..9c4afa89c41a6 100644 --- a/posthog/queries/trends/trends_actors.py +++ b/posthog/queries/trends/trends_actors.py @@ -16,7 +16,7 @@ is_series_group_based, process_math, ) -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class TrendsActors(ActorBaseQuery): @@ -104,7 +104,7 @@ def actor_query(self, limit_actors: Optional[bool] = True) -> Tuple[str, Dict]: team=self._team, entity=self.entity, should_join_distinct_ids=not self.is_aggregating_by_groups - and self._team.person_on_events_mode != PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS, + and self._team.person_on_events_mode != PersonsOnEventsMode.person_id_no_override_properties_on_events, extra_event_properties=["$window_id", "$session_id"] if self._filter.include_recordings else [], extra_fields=extra_fields, person_on_events_mode=self._team.person_on_events_mode, diff --git a/posthog/queries/trends/trends_event_query.py b/posthog/queries/trends/trends_event_query.py index d3bcc9f381290..bc9e9b979bd00 100644 --- a/posthog/queries/trends/trends_event_query.py +++ b/posthog/queries/trends/trends_event_query.py @@ -2,7 +2,7 @@ from posthog.models.property.util import get_property_string_expr from posthog.queries.trends.trends_event_query_base import TrendsEventQueryBase -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class TrendsEventQuery(TrendsEventQueryBase): @@ -10,7 +10,7 @@ def get_query(self) -> Tuple[str, Dict[str, Any]]: person_id_field = "" if self._should_join_distinct_ids: person_id_field = f", {self._person_id_alias} as person_id" - elif self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + elif self._person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: person_id_field = f", {self.EVENT_TABLE_ALIAS}.person_id as person_id" _fields = ( @@ -62,7 +62,7 @@ def get_query(self) -> Tuple[str, Dict[str, Any]]: return f"SELECT {_fields} {base_query}", params def _get_extra_person_columns(self) -> str: - if self._person_on_events_mode != PersonOnEventsMode.DISABLED: + if self._person_on_events_mode != PersonsOnEventsMode.disabled: return " ".join( ", {extract} as {column_name}".format( extract=get_property_string_expr( diff --git a/posthog/queries/trends/trends_event_query_base.py b/posthog/queries/trends/trends_event_query_base.py index 082aed8e556a0..dbeb9f17cdc3d 100644 --- a/posthog/queries/trends/trends_event_query_base.py +++ b/posthog/queries/trends/trends_event_query_base.py @@ -18,7 +18,7 @@ get_active_user_params, ) from posthog.queries.util import get_person_properties_mode -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class TrendsEventQueryBase(EventQuery): @@ -80,7 +80,7 @@ def get_query_base(self) -> Tuple[str, Dict[str, Any]]: return query, self.params def _determine_should_join_distinct_ids(self) -> None: - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + if self._person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: self._should_join_distinct_ids = False is_entity_per_user = self._entity.math in ( @@ -97,7 +97,7 @@ def _determine_should_join_distinct_ids(self) -> None: self._should_join_distinct_ids = True def _determine_should_join_persons(self) -> None: - if self._person_on_events_mode != PersonOnEventsMode.DISABLED: + if self._person_on_events_mode != PersonsOnEventsMode.disabled: self._should_join_persons = False else: EventQuery._determine_should_join_persons(self) @@ -107,7 +107,7 @@ def _get_not_null_actor_condition(self) -> str: # If aggregating by person, exclude events with null/zero person IDs return ( f"AND notEmpty({self.EVENT_TABLE_ALIAS}.person_id)" - if self._person_on_events_mode != PersonOnEventsMode.DISABLED + if self._person_on_events_mode != PersonsOnEventsMode.disabled else "" ) else: diff --git a/posthog/queries/trends/util.py b/posthog/queries/trends/util.py index b91e4d6ac185d..bb11f0c38293d 100644 --- a/posthog/queries/trends/util.py +++ b/posthog/queries/trends/util.py @@ -23,7 +23,7 @@ from posthog.models.property.util import get_property_string_expr from posthog.models.team import Team from posthog.queries.util import correct_result_for_sampling, get_earliest_timestamp -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode logger = structlog.get_logger(__name__) @@ -174,9 +174,9 @@ def determine_aggregator(entity: Entity, team: Team) -> str: return f'"$group_{entity.math_group_type_index}"' elif team.aggregate_users_by_distinct_id: return "e.distinct_id" - elif team.person_on_events_mode == PersonOnEventsMode.PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS: + elif team.person_on_events_mode == PersonsOnEventsMode.person_id_no_override_properties_on_events: return "e.person_id" - elif team.person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS: + elif team.person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events: return f"if(notEmpty(overrides.person_id), overrides.person_id, e.person_id)" else: return "pdi.person_id" diff --git a/posthog/queries/util.py b/posthog/queries/util.py index be08fb732c8ce..e366fb1cc7833 100644 --- a/posthog/queries/util.py +++ b/posthog/queries/util.py @@ -12,7 +12,7 @@ from posthog.models.team import Team from posthog.models.team.team import WeekStartDay from posthog.queries.insight import insight_sync_execute -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode class PersonPropertiesMode(Enum): @@ -175,10 +175,10 @@ def correct_result_for_sampling( def get_person_properties_mode(team: Team) -> PersonPropertiesMode: - if team.person_on_events_mode == PersonOnEventsMode.DISABLED: + if team.person_on_events_mode == PersonsOnEventsMode.disabled: return PersonPropertiesMode.USING_PERSON_PROPERTIES_COLUMN - if team.person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS: + if team.person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events: return PersonPropertiesMode.DIRECT_ON_EVENTS_WITH_POE_V2 return PersonPropertiesMode.DIRECT_ON_EVENTS diff --git a/posthog/session_recordings/queries/session_recording_list_from_replay_summary.py b/posthog/session_recordings/queries/session_recording_list_from_replay_summary.py index 4ff24160ae3e6..4f64fff7f8ab3 100644 --- a/posthog/session_recordings/queries/session_recording_list_from_replay_summary.py +++ b/posthog/session_recordings/queries/session_recording_list_from_replay_summary.py @@ -14,7 +14,7 @@ from posthog.models.filters.session_recordings_filter import SessionRecordingsFilter from posthog.models.property import PropertyGroup from posthog.models.property.util import parse_prop_grouped_clauses -from posthog.models.team import PersonOnEventsMode +from posthog.models.team import PersonsOnEventsMode from posthog.queries.event_query import EventQuery from posthog.queries.util import PersonPropertiesMode from posthog.session_recordings.queries.session_replay_events import ttl_days @@ -197,7 +197,7 @@ def _data_to_return(self, results: List[Any]) -> List[Dict[str, Any]]: def get_query(self) -> Tuple[str, Dict[str, Any]]: # we don't support PoE V1 - hopefully that's ok - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS: + if self._person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events: return "", {} prop_query, prop_params = self._get_prop_groups( @@ -302,7 +302,7 @@ def _determine_should_join_events(self): ) has_poe_filters = ( - self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS + self._person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events and len( [ pg @@ -314,7 +314,7 @@ def _determine_should_join_events(self): ) has_poe_person_filter = ( - self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS + self._person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events and self._filter.person_uuid ) @@ -371,7 +371,7 @@ def format_event_filter(self, entity: Entity, prepend: str, team_id: int) -> Tup allow_denormalized_props=True, has_person_id_joined=True, person_properties_mode=PersonPropertiesMode.DIRECT_ON_EVENTS_WITH_POE_V2 - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS + if self._person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events else PersonPropertiesMode.USING_PERSON_PROPERTIES_COLUMN, hogql_context=self._filter.hogql_context, ) @@ -416,7 +416,7 @@ def build_event_filters(self) -> SummaryEventFiltersSQL: -- select the unique events in this session to support filtering sessions by presence of an event groupUniqArray(event) as event_names,""" - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS: + if self._person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events: person_id_clause, person_id_params = self._get_person_id_clause condition_sql += person_id_clause params = {**params, **person_id_params} @@ -493,7 +493,7 @@ def get_query(self, select_event_ids: bool = False) -> Tuple[str, Dict[str, Any] g for g in self._filter.property_groups.flat if ( - self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS + self._person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events and g.type == "person" ) or ( @@ -509,7 +509,7 @@ def get_query(self, select_event_ids: bool = False) -> Tuple[str, Dict[str, Any] # but would need careful monitoring allow_denormalized_props=settings.ALLOW_DENORMALIZED_PROPS_IN_LISTING, person_properties_mode=PersonPropertiesMode.DIRECT_ON_EVENTS_WITH_POE_V2 - if self._person_on_events_mode == PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS + if self._person_on_events_mode == PersonsOnEventsMode.person_id_override_properties_on_events else PersonPropertiesMode.USING_PERSON_PROPERTIES_COLUMN, ) diff --git a/posthog/test/test_team.py b/posthog/test/test_team.py index c6e9a681b4839..ea40559b48e69 100644 --- a/posthog/test/test_team.py +++ b/posthog/test/test_team.py @@ -15,7 +15,7 @@ from posthog.models.project import Project from posthog.models.team import get_team_in_cache, util from posthog.plugins.test.mock import mocked_plugin_requests_get -from posthog.utils import PersonOnEventsMode +from posthog.schema import PersonsOnEventsMode from .base import BaseTest @@ -138,7 +138,9 @@ def test_team_on_cloud_uses_feature_flag_to_determine_person_on_events(self, moc with self.is_cloud(True): with override_instance_config("PERSON_ON_EVENTS_ENABLED", False): team = Team.objects.create_with_data(organization=self.organization) - self.assertEqual(team.person_on_events_mode, PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS) + self.assertEqual( + team.person_on_events_mode, PersonsOnEventsMode.person_id_override_properties_on_events + ) # called more than once when evaluating hogql mock_feature_enabled.assert_called_with( "persons-on-events-v2-reads-enabled", @@ -159,12 +161,14 @@ def test_team_on_self_hosted_uses_instance_setting_to_determine_person_on_events with self.is_cloud(False): with override_instance_config("PERSON_ON_EVENTS_V2_ENABLED", True): team = Team.objects.create_with_data(organization=self.organization) - self.assertEqual(team.person_on_events_mode, PersonOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS) + self.assertEqual( + team.person_on_events_mode, PersonsOnEventsMode.person_id_override_properties_on_events + ) mock_feature_enabled.assert_not_called() with override_instance_config("PERSON_ON_EVENTS_V2_ENABLED", False): team = Team.objects.create_with_data(organization=self.organization) - self.assertEqual(team.person_on_events_mode, PersonOnEventsMode.DISABLED) + self.assertEqual(team.person_on_events_mode, PersonsOnEventsMode.disabled) mock_feature_enabled.assert_not_called() def test_each_team_gets_project_with_default_name_and_same_id(self): diff --git a/posthog/utils.py b/posthog/utils.py index 72c8d73d988fd..f186fdadb4adb 100644 --- a/posthog/utils.py +++ b/posthog/utils.py @@ -1304,13 +1304,6 @@ def patch(wrapper): return inner -class PersonOnEventsMode(str, Enum): - DISABLED = "disabled" - PERSON_ID_NO_OVERRIDE_PROPERTIES_ON_EVENTS = "person_id_no_override_properties_on_events" - PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS = "person_id_override_properties_on_events" - PERSON_ID_OVERRIDE_PROPERTIES_JOINED = "person_id_override_properties_joined" - - def label_for_team_id_to_track(team_id: int) -> str: team_id_filter: List[str] = settings.DECIDE_TRACK_TEAM_IDS