Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(filters): delete mixins no surviving filter inherits (#104271)

Thomas Obermüllerc96afe3f881e
diff --git a/posthog/constants.py b/posthog/constants.py
index 75748b422642..ef18e2cd9949 100644
--- a/posthog/constants.py
+++ b/posthog/constants.py
@@ -155,15 +155,12 @@ DATA_WAREHOUSE_ENTITIES = "data_warehouse_entities"
EXCLUSIONS = "exclusions"
PROPERTIES = "properties"
PROPERTY_GROUPS = "property_groups"
-SELECTOR = "selector"
INTERVAL = "interval"
-SMOOTHING_INTERVALS = "smoothing_intervals"
DISPLAY = "display"
SHOWN_AS = "shown_as"
CLIENT_QUERY_ID = "client_query_id"
FILTER_TEST_ACCOUNTS = "filter_test_accounts"
BREAKDOWN_TYPE = "breakdown_type"
-BREAKDOWN_VALUE = "breakdown_value"
BREAKDOWN_GROUP_TYPE_INDEX = "breakdown_group_type_index"
COMPARE = "compare"
COMPARE_TO = "compare_to"
@@ -191,35 +188,21 @@ STICKINESS_DAYS = "stickiness_days"
ENTITY_ID = "entity_id"
ENTITY_TYPE = "entity_type"
ENTITY_MATH = "entity_math"
-FUNNEL_WINDOW_DAYS = "funnel_window_days"
FUNNEL_WINDOW_INTERVAL_UNIT = "funnel_window_interval_unit"
FUNNEL_WINDOW_INTERVAL = "funnel_window_interval"
FUNNEL_FROM_STEP = "funnel_from_step"
FUNNEL_TO_STEP = "funnel_to_step"
FUNNEL_STEP = "funnel_step"
FUNNEL_CUSTOM_STEPS = "funnel_custom_steps"
-FUNNEL_STEP_BREAKDOWN = "funnel_step_breakdown"
-FUNNEL_LAYOUT = "layout"
-FUNNEL_AGGREAGTE_BY_HOGQL = "funnel_aggregate_by_hogql"
-FUNNEL_ORDER_TYPE = "funnel_order_type"
-FUNNEL_VIZ_TYPE = "funnel_viz_type"
FUNNEL_CORRELATION_TYPE = "funnel_correlation_type"
FUNNEL_WINDOW_INTERVAL_TYPES = Literal["DAY", "SECOND", "MINUTE", "HOUR", "WEEK", "MONTH"]
# Funnel Correlation Properties
FUNNEL_CORRELATION_NAMES = "funnel_correlation_names"
FUNNEL_CORRELATION_EXCLUDE_NAMES = "funnel_correlation_exclude_names"
-FUNNEL_CORRELATION_PROPERTY_VALUES = "funnel_correlation_property_values"
# Funnel Correlation Events
FUNNEL_CORRELATION_EVENT_NAMES = "funnel_correlation_event_names"
FUNNEL_CORRELATION_EXCLUDE_EVENT_NAMES = "funnel_correlation_exclude_event_names"
FUNNEL_CORRELATION_EVENT_EXCLUDE_PROPERTY_NAMES = "funnel_correlation_event_exclude_property_names"
-FUNNEL_CORRELATION_PERSON_ENTITY = "funnel_correlation_person_entity"
-FUNNEL_CORRELATION_PERSON_LIMIT = "funnel_correlation_person_limit"
-FUNNEL_CORRELATION_PERSON_OFFSET = "funnel_correlation_person_offset"
-FUNNEL_CORRELATION_PERSON_CONVERTED = "funnel_correlation_person_converted"
-BIN_COUNT = "bin_count"
-ENTRANCE_PERIOD_START = "entrance_period_start"
-DROP_OFF = "drop_off"
FUNNEL_PATHS = "funnel_paths"
PATHS_HOGQL_EXPRESSION = "paths_hogql_expression"
PATHS_INCLUDE_EVENT_TYPES = "include_event_types"
diff --git a/posthog/models/filters/mixins/common.py b/posthog/models/filters/mixins/common.py
index 2f69d5342479..5e66a425e167 100644
--- a/posthog/models/filters/mixins/common.py
+++ b/posthog/models/filters/mixins/common.py
@@ -1,7 +1,7 @@
import json
import datetime
from math import ceil
-from typing import Any, Literal, Optional, Union, cast
+from typing import Any, Literal, Optional, Union
from zoneinfo import ZoneInfo
from django.utils import timezone
@@ -22,7 +22,6 @@ from posthog.constants import (
BREAKDOWN_LIMIT,
BREAKDOWN_NORMALIZE_URL,
BREAKDOWN_TYPE,
- BREAKDOWN_VALUE,
BREAKDOWNS,
CLIENT_QUERY_ID,
COMPARE,
@@ -42,9 +41,7 @@ from posthog.constants import (
LIMIT,
OFFSET,
SAMPLING_FACTOR,
- SELECTOR,
SHOWN_AS,
- SMOOTHING_INTERVALS,
TREND_FILTER_TYPE_ACTIONS,
TREND_FILTER_TYPE_DATA_WAREHOUSE,
TREND_FILTER_TYPE_EVENTS,
@@ -58,35 +55,6 @@ from posthog.models.filters.utils import GroupTypeIndex, validate_group_type_ind
from posthog.utils import DEFAULT_DATE_FROM_DAYS, relative_date_parse_with_delta_mapping
-class SmoothingIntervalsMixin(BaseParamMixin):
- @cached_property
- def smoothing_intervals(self) -> int:
- interval_candidate_string = self._data.get(SMOOTHING_INTERVALS)
- if not interval_candidate_string:
- return 1
- try:
- interval_candidate = int(interval_candidate_string)
- if interval_candidate < 1:
- raise ValueError(f"Smoothing intervals must be a positive integer!")
- except ValueError:
- raise ValueError(f"Smoothing intervals must be a positive integer!")
- return cast(int, interval_candidate)
-
- @include_dict
- def smoothing_intervals_to_dict(self):
- return {SMOOTHING_INTERVALS: self.smoothing_intervals}
-
-
-class SelectorMixin(BaseParamMixin):
- @cached_property
- def selector(self) -> Optional[str]:
- return self._data.get(SELECTOR, None)
-
- @include_dict
- def selector_to_dict(self):
- return {"selector": self.selector} if self.selector else {}
-
-
class ShownAsMixin(BaseParamMixin):
@cached_property
def shown_as(self) -> Optional[str]:
@@ -262,16 +230,6 @@ class BreakdownMixin(BaseParamMixin):
return {}
-class BreakdownValueMixin(BaseParamMixin):
- @cached_property
- def breakdown_value(self) -> Optional[str]:
- return self._data.get(BREAKDOWN_VALUE, None)
-
- @include_dict
- def breakdown_value_to_dict(self):
- return {"breakdown_value": self.breakdown_value} if self.breakdown_value else {}
-
-
class InsightMixin(BaseParamMixin):
@cached_property
def insight(self) -> Literal["TRENDS", "FUNNELS", "RETENTION", "PATHS", "LIFECYCLE", "STICKINESS"]:
@@ -575,39 +533,6 @@ class SearchMixin(BaseParamMixin):
return {"search": self.search} if self.search else {}
-class DistinctIdMixin(BaseParamMixin):
- """
- Filter on distinct id. Only used for person endpoint
- """
-
- @cached_property
- def distinct_id(self) -> Optional[str]:
- distinct_id = self._data.get("distinct_id", None)
- return distinct_id
-
-
-class EmailMixin(BaseParamMixin):
- """
- Filter on email. Only used for person endpoint
- """
-
- @cached_property
- def email(self) -> Optional[str]:
- email = self._data.get("email", None)
- return email
-
-
-class UpdatedAfterMixin(BaseParamMixin):
- """
- Filter on updated after (parsable by CH parseDateTimeBestEffort). Only used for person endpoint
- """
-
- @cached_property
- def updated_after(self) -> Optional[str]:
- updated_after = self._data.get("updated_after", None)
- return updated_after
-
-
class SampleMixin(BaseParamMixin):
"""
Sample factor for a query.
diff --git a/posthog/models/filters/mixins/funnel.py b/posthog/models/filters/mixins/funnel.py
index 32374d29c931..d89db3a0c4db 100644
--- a/posthog/models/filters/mixins/funnel.py
+++ b/posthog/models/filters/mixins/funnel.py
@@ -1,53 +1,26 @@
import json
-import datetime
-from typing import TYPE_CHECKING, Literal, Optional, Union
-
-from posthog.models.property import Property
-
-if TYPE_CHECKING:
- from posthog.models.entity import Entity
+from typing import Optional
from rest_framework.exceptions import ValidationError
from posthog.constants import (
- BIN_COUNT,
- DISPLAY,
- DROP_OFF,
- ENTRANCE_PERIOD_START,
- FUNNEL_AGGREAGTE_BY_HOGQL,
FUNNEL_CORRELATION_EVENT_EXCLUDE_PROPERTY_NAMES,
FUNNEL_CORRELATION_EVENT_NAMES,
FUNNEL_CORRELATION_EXCLUDE_EVENT_NAMES,
FUNNEL_CORRELATION_EXCLUDE_NAMES,
FUNNEL_CORRELATION_NAMES,
- FUNNEL_CORRELATION_PERSON_CONVERTED,
- FUNNEL_CORRELATION_PERSON_ENTITY,
- FUNNEL_CORRELATION_PERSON_LIMIT,
- FUNNEL_CORRELATION_PERSON_OFFSET,
- FUNNEL_CORRELATION_PROPERTY_VALUES,
FUNNEL_CORRELATION_TYPE,
FUNNEL_CUSTOM_STEPS,
FUNNEL_FROM_STEP,
- FUNNEL_LAYOUT,
- FUNNEL_ORDER_TYPE,
FUNNEL_STEP,
- FUNNEL_STEP_BREAKDOWN,
FUNNEL_TO_STEP,
- FUNNEL_VIZ_TYPE,
- FUNNEL_WINDOW_DAYS,
FUNNEL_WINDOW_INTERVAL,
FUNNEL_WINDOW_INTERVAL_TYPES,
FUNNEL_WINDOW_INTERVAL_UNIT,
- INSIGHT,
- INSIGHT_FUNNELS,
- TRENDS_LINEAR,
FunnelCorrelationType,
- FunnelOrderType,
- FunnelVizType,
)
from posthog.models.filters.mixins.base import BaseParamMixin, FunnelWindowIntervalType
from posthog.models.filters.mixins.utils import cached_property, include_dict
-from posthog.utils import relative_date_parse, str_to_bool
class FunnelFromToStepsMixin(BaseParamMixin):
@@ -73,29 +46,6 @@ class FunnelFromToStepsMixin(BaseParamMixin):
return dict_part
-class FunnelWindowDaysMixin(BaseParamMixin):
- @cached_property
- def funnel_window_days(self) -> Optional[int]:
- _days = int(self._data.get(FUNNEL_WINDOW_DAYS, "0"))
- if _days == 0:
- return None
- return _days
-
- @include_dict
- def funnel_window_days_to_dict(self):
- return {FUNNEL_WINDOW_DAYS: self.funnel_window_days} if self.funnel_window_days else {}
-
- @staticmethod
- def milliseconds_from_days(days):
- milliseconds, seconds, minutes, hours = [1000, 60, 60, 24]
- return milliseconds * seconds * minutes * hours * days
-
- @staticmethod
- def microseconds_from_days(days):
- microseconds = 1000
- return microseconds * FunnelWindowDaysMixin.milliseconds_from_days(days)
-
-
class FunnelWindowMixin(BaseParamMixin):
@cached_property
def funnel_window_interval(self) -> Optional[int]:
@@ -174,117 +124,6 @@ class FunnelPersonsStepMixin(BaseParamMixin):
return result
-class FunnelPersonsStepBreakdownMixin(BaseParamMixin):
- @cached_property
- def funnel_step_breakdown(self) -> Optional[Union[list[str], int, str]]:
- """
- The breakdown value for which to get persons for.
-
- For person and event properties as this value is set within the funnel it is always an array.
- Until multi property breakdowns is released it is always a single value array
-
- for groups it is always a string
-
- for cohorts it is always an int
- """
- raw: Optional[str] = self._data.get(FUNNEL_STEP_BREAKDOWN)
- if not raw:
- return raw
-
- try:
- return json.loads(raw)
- except (TypeError, json.decoder.JSONDecodeError):
- return raw
-
- @include_dict
- def funnel_person_breakdown_to_dict(self):
- return {FUNNEL_STEP_BREAKDOWN: self.funnel_step_breakdown} if self.funnel_step_breakdown is not None else {}
-
-
-class FunnelLayoutMixin(BaseParamMixin):
- @cached_property
- def layout(self) -> Optional[Literal["horizontal", "vertical"]]:
- return self._data.get(FUNNEL_LAYOUT)
-
- @include_dict
- def layout_to_dict(self):
- return {FUNNEL_LAYOUT: self.layout} if self.layout else {}
-
-
-class FunnelHogQLAggregationMixin(BaseParamMixin):
- @cached_property
- def funnel_aggregate_by_hogql(self) -> Optional[str]:
- return self._data.get(FUNNEL_AGGREAGTE_BY_HOGQL)
-
- @include_dict
- def funnel_aggregate_by_hogql_to_dict(self):
- return {FUNNEL_AGGREAGTE_BY_HOGQL: self.funnel_aggregate_by_hogql} if self.funnel_aggregate_by_hogql else {}
-
-
-class FunnelTypeMixin(BaseParamMixin):
- @cached_property
- def funnel_order_type(self) -> Optional[FunnelOrderType]:
- return self._data.get(FUNNEL_ORDER_TYPE)
-
- @cached_property
- def funnel_viz_type(self) -> Optional[FunnelVizType]:
- funnel_viz_type = self._data.get(FUNNEL_VIZ_TYPE)
- if (
- funnel_viz_type is None
- and self._data.get(INSIGHT) == INSIGHT_FUNNELS
- and self._data.get(DISPLAY) == TRENDS_LINEAR
- ):
- # Backwards compatibility
- # Before Filter.funnel_viz_type funnel trends were indicated by Filter.display being TRENDS_LINEAR
- return FunnelVizType.TRENDS
- return funnel_viz_type
-
- @include_dict
- def funnel_type_to_dict(self):
- result: dict[str, str] = {}
- if self.funnel_order_type:
- result[FUNNEL_ORDER_TYPE] = self.funnel_order_type
- if self.funnel_viz_type:
- result[FUNNEL_VIZ_TYPE] = self.funnel_viz_type
- return result
-
-
-class HistogramMixin(BaseParamMixin):
- @cached_property
- def bin_count(self) -> Optional[int]:
- bin_count = self._data.get(BIN_COUNT)
- return int(bin_count) if bin_count else None
-
- @include_dict
- def histogram_to_dict(self):
- return {"bin_count": self.bin_count} if self.bin_count else {}
-
-
-class FunnelTrendsPersonsMixin(BaseParamMixin):
- @cached_property
- def entrance_period_start(self) -> Optional[datetime.datetime]:
- entrance_period_start_raw = self._data.get(ENTRANCE_PERIOD_START)
- return (
- relative_date_parse(entrance_period_start_raw, self.team.timezone_info) # type: ignore
- if entrance_period_start_raw
- else None
- )
-
- @cached_property
- def drop_off(self) -> Optional[bool]:
- drop_off_raw = self._data.get(DROP_OFF)
- return str_to_bool(str(drop_off_raw)) if drop_off_raw is not None else None
-
- @include_dict
- def funnel_trends_persons_to_dict(self):
- result_dict: dict = {}
- if self.entrance_period_start:
- result_dict[ENTRANCE_PERIOD_START] = self.entrance_period_start.isoformat()
- if self.drop_off is not None:
- result_dict[DROP_OFF] = self.drop_off
- return result_dict
-
-
class FunnelCorrelationMixin(BaseParamMixin):
@cached_property
def correlation_type(self) -> Optional[FunnelCorrelationType]:
@@ -353,98 +192,3 @@ class FunnelCorrelationMixin(BaseParamMixin):
if self.correlation_event_exclude_property_names:
result_dict[FUNNEL_CORRELATION_EVENT_EXCLUDE_PROPERTY_NAMES] = self.correlation_event_exclude_property_names
return result_dict
-
-
-class FunnelCorrelationActorsMixin(BaseParamMixin):
- @cached_property
- def correlation_person_entity(self) -> Optional["Entity"]:
- # Used for event & event_with_properties correlations persons
- from posthog.models.entity import Entity
-
- raw_event = self._data.get(FUNNEL_CORRELATION_PERSON_ENTITY)
- if isinstance(raw_event, str):
- event = json.loads(raw_event)
- else:
- event = raw_event
-
- return Entity(event) if event else None
-
- @cached_property
- def correlation_property_values(self) -> Optional[list[Property]]:
- # Used for property correlations persons
-
- _props = self._data.get(FUNNEL_CORRELATION_PROPERTY_VALUES)
-
- if not _props:
- return None
-
- if isinstance(_props, str):
- try:
- loaded_props = json.loads(_props)
- except json.decoder.JSONDecodeError:
- raise ValidationError("Properties are unparsable!")
- else:
- loaded_props = _props
-
- if isinstance(loaded_props, list):
- _properties = []
- for prop_params in loaded_props:
- if isinstance(prop_params, Property):
- _properties.append(prop_params)
- else:
- try:
- new_prop = Property(**prop_params)
- _properties.append(new_prop)
- except:
- continue
- return _properties
- return None
-
- @cached_property
- def correlation_person_limit(self) -> int:
- limit = self._data.get(FUNNEL_CORRELATION_PERSON_LIMIT)
- return int(limit) if limit else 0
-
- @cached_property
- def correlation_person_offset(self) -> int:
- offset = self._data.get(FUNNEL_CORRELATION_PERSON_OFFSET)
- return int(offset) if offset else 0
-
- @cached_property
- def correlation_persons_converted(self) -> Optional[bool]:
- converted = self._data.get(FUNNEL_CORRELATION_PERSON_CONVERTED)
- if not converted:
- return None
- if converted.lower() == "true":
- return True
- return False
-
- @include_dict
- def funnel_correlation_persons_to_dict(self):
- result_dict: dict = {}
- if self.correlation_person_entity:
- result_dict[FUNNEL_CORRELATION_PERSON_ENTITY] = self.correlation_person_entity.to_dict()
- if self.correlation_property_values:
- result_dict[FUNNEL_CORRELATION_PROPERTY_VALUES] = [
- prop.to_dict() for prop in self.correlation_property_values
- ]
- if self.correlation_person_limit:
- result_dict[FUNNEL_CORRELATION_PERSON_LIMIT] = self.correlation_person_limit
- if self.correlation_person_offset:
- result_dict[FUNNEL_CORRELATION_PERSON_OFFSET] = self.correlation_person_offset
- if self.correlation_persons_converted is not None:
- result_dict[FUNNEL_CORRELATION_PERSON_CONVERTED] = self.correlation_persons_converted
- return result_dict
-
- @cached_property
- def include_final_matching_events(self) -> bool:
- # If true, actor query will include the user's final event in the funnel for recordings
- return self._data.get("include_final_matching_events", False)
-
- @include_dict
- def include_final_matching_events_to_dict(self):
- return (
- {"include_final_matching_events": self.include_final_matching_events}
- if self.include_final_matching_events
- else {}
- )
diff --git a/posthog/models/filters/test/test_filter_mixins.py b/posthog/models/filters/test/test_filter_mixins.py
deleted file mode 100644
index a432f62037a2..000000000000
--- a/posthog/models/filters/test/test_filter_mixins.py
+++ /dev/null
@@ -1,18 +0,0 @@
-from posthog.test.base import BaseTest
-
-from posthog.models.filters.mixins.funnel import FunnelWindowDaysMixin
-
-
-class TestFilterMixins(BaseTest):
- def test_funnel_window_days_to_microseconds(self):
- one_day = FunnelWindowDaysMixin.microseconds_from_days(1)
- two_days = FunnelWindowDaysMixin.microseconds_from_days(2)
- three_days = FunnelWindowDaysMixin.microseconds_from_days(3)
-
- self.assertEqual(86_400_000_000, one_day)
- self.assertEqual(17_2800_000_000, two_days)
- self.assertEqual(259_200_000_000, three_days)
-
- def test_funnel_window_days_to_milliseconds(self):
- one_day = FunnelWindowDaysMixin.milliseconds_from_days(1)
- self.assertEqual(one_day, 86_400_000)
diff --git a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
index 433f7682fa6c..9a56bbcc4d84 100644
--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
@@ -131,7 +131,6 @@ posthog/kafka_client/test/test_client.py::KafkaClientRoundtripTestCase
posthog/management/commands/test/test_analyze_migration_risk.py::TestAnalyzeMigrationRisk
posthog/management/commands/test/test_base_hypercache_command.py::TestVerificationResultsErrorReporting
posthog/management/commands/test/test_survey_cohort_bytecode_stl.py::TestBytecodeWalker
-posthog/models/filters/test/test_filter_mixins.py::TestFilterMixins
posthog/models/filters/test/test_path_filter.py::TestPathFilter
posthog/models/property/test/test_property_behavioral_validation.py::TestBehavioralPropertyBytecodeCondition
posthog/models/property/test/test_property_behavioral_validation.py::TestBehavioralPropertyDateRangeValidation