: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(cohorts): accept explicit_datetime on performed_event_sequence filters (#118708)
posthog[bot]79ad221a5622
diff --git a/ee/clickhouse/queries/test/test_cohort_query.py b/ee/clickhouse/queries/test/test_cohort_query.pyindex e13236fcac81..8ced19d78884 100644--- a/ee/clickhouse/queries/test/test_cohort_query.py+++ b/ee/clickhouse/queries/test/test_cohort_query.py@@ -13,6 +13,7 @@ from posthog.test.base import (flush_persons_and_events,)+from parameterized import parameterizedfrom rest_framework.exceptions import ValidationErrorfrom posthog.schema import PersonsOnEventsMode@@ -2376,7 +2377,18 @@ class TestCohortQuery(ClickhouseTestMixin, BaseTest):assert sorted([p1.uuid, p2.uuid]) == sorted([r[0] for r in res])- def test_performed_event_sequence(self):+ @parameterized.expand(+ [+ ("time_value", {"time_interval": "day", "time_value": 7}, True),+ ("explicit_datetime", {"explicit_datetime": "-7d"}, True),+ (+ "explicit_datetime_range_before_sequence",+ {"explicit_datetime": "-7d", "explicit_datetime_to": "-4d"},+ False,+ ),+ ]+ )+ def test_performed_event_sequence(self, _name: str, time_bound: dict[str, Any], p1_matches: bool) -> None:p1 = _create_person(team_id=self.team.pk,distinct_ids=["p1"],@@ -2408,8 +2420,7 @@ class TestCohortQuery(ClickhouseTestMixin, BaseTest):{"key": "$pageview","event_type": "events",- "time_interval": "day",- "time_value": 7,+ **time_bound,"seq_time_interval": "day","seq_time_value": 3,"seq_event": "$pageview",@@ -2424,7 +2435,7 @@ class TestCohortQuery(ClickhouseTestMixin, BaseTest):res = execute(filter, self.team)- assert [p1.uuid] == [r[0] for r in res]+ assert ([p1.uuid] if p1_matches else []) == [r[0] for r in res]@also_test_with_materialized_columns(event_properties=["$current_url"])def test_performed_event_sequence_with_action(self):diff --git a/posthog/models/property/property.py b/posthog/models/property/property.pyindex 805288823a71..487f8d592a10 100644--- a/posthog/models/property/property.py+++ b/posthog/models/property/property.py@@ -155,6 +155,10 @@ VALIDATE_CONDITIONAL_BEHAVIORAL_PROP_TYPES = {{"time_value", "time_interval"},{"explicit_datetime"},],+ BehavioralPropertyType.PERFORMED_EVENT_SEQUENCE: [+ {"time_value", "time_interval"},+ {"explicit_datetime"},+ ],}# Mirrored in frontend/src/models/cohortsModel.ts (BEHAVIORAL_VALUE_ALIASES) so the cohort@@ -192,8 +196,6 @@ VALIDATE_BEHAVIORAL_PROP_TYPES = {"key","value","event_type",- "time_value",- "time_interval","seq_event_type","seq_event","seq_time_value",diff --git a/posthog/models/property/test/test_property_behavioral_validation.py b/posthog/models/property/test/test_property_behavioral_validation.pyindex 936018da2630..23cea32ccd23 100644--- a/posthog/models/property/test/test_property_behavioral_validation.py+++ b/posthog/models/property/test/test_property_behavioral_validation.py@@ -1,9 +1,18 @@+from typing import Any+from django.test import SimpleTestCasefrom parameterized import parameterizedfrom posthog.models.property import BehavioralPropertyType, Property+SEQUENCE_FIELDS: dict[str, Any] = {+ "seq_event_type": "events",+ "seq_event": "$pageleave",+ "seq_time_value": 1,+ "seq_time_interval": "day",+}+class TestBehavioralPropertyDateRangeValidation(SimpleTestCase):"""Validation of the explicit_datetime / explicit_datetime_to combo on behavioral cohort filters."""@@ -79,6 +88,26 @@ class TestBehavioralPropertyDateRangeValidation(SimpleTestCase):explicit_datetime_to="-7d",)+ @parameterized.expand(+ [+ ("explicit_datetime", {"explicit_datetime": "-30d"}),+ ("explicit_datetime_range", {"explicit_datetime": "-30d", "explicit_datetime_to": "-7d"}),+ ("time_value_interval", {"time_value": 30, "time_interval": "day"}),+ ]+ )+ def test_performed_event_sequence_accepts_time_bound(self, _name: str, time_bound: dict[str, Any]) -> None:+ self._build(value=BehavioralPropertyType.PERFORMED_EVENT_SEQUENCE, **SEQUENCE_FIELDS, **time_bound)++ @parameterized.expand(+ [+ ("no_time_fields", {}),+ ("only_upper_bound", {"explicit_datetime_to": "-7d"}),+ ]+ )+ def test_performed_event_sequence_rejects_missing_time_bound(self, _name: str, time_bound: dict[str, Any]) -> None:+ with self.assertRaises(ValueError):+ self._build(value=BehavioralPropertyType.PERFORMED_EVENT_SEQUENCE, **SEQUENCE_FIELDS, **time_bound)+class TestBehavioralPropertyValueAlias(SimpleTestCase):"""Some cohort filter generators store "performed_event_multiple_times" instead of