: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
feat(ingestion): add the event filter pipeline override model (#120983)
Paweł Ledwoń2c2a637838c8
diff --git a/.semgrep/rules/security/idor-team-scoped-models.yaml b/.semgrep/rules/security/idor-team-scoped-models.yamlindex 7f5d4db587b2..b552e2367288 100644--- a/.semgrep/rules/security/idor-team-scoped-models.yaml+++ b/.semgrep/rules/security/idor-team-scoped-models.yaml@@ -184,6 +184,7 @@ rules:|EnterpriseEventDefinition|EnterprisePropertyDefinition|EventFilterConfig+ |EventFilterPipelineOverride|EventStream|EventStreamMember|ErrorTrackingAlert@@ -668,6 +669,7 @@ rules:|EnterpriseEventDefinition|EnterprisePropertyDefinition|EventFilterConfig+ |EventFilterPipelineOverride|EventStream|EventStreamMember|ErrorTrackingAlert@@ -1103,6 +1105,7 @@ rules:|EvaluationReport|Event|EventFilterConfig+ |EventFilterPipelineOverride|ExperimentTimeseriesRecalculation|ExplicitTeamMembership|ExportedAssetdiff --git a/posthog/migrations/1413_event_filter_pipeline_override.py b/posthog/migrations/1413_event_filter_pipeline_override.pynew file mode 100644index 000000000000..bf1a119392e8--- /dev/null+++ b/posthog/migrations/1413_event_filter_pipeline_override.py@@ -0,0 +1,71 @@+# Generated by Django 5.2.18 on 2026-10-21 09:21++import django.db.models.manager+import django.db.models.deletion+from django.conf import settings+from django.db import migrations, models++import posthog.models.utils+import posthog.models.event_filter_config+++class Migration(migrations.Migration):+ dependencies = [("posthog", "1412_drop_retired_desktop_file_system_tables")]++ operations = [+ migrations.CreateModel(+ name="EventFilterPipelineOverride",+ fields=[+ (+ "id",+ models.UUIDField(+ default=posthog.models.utils.uuid7,+ editable=False,+ primary_key=True,+ serialize=False,+ ),+ ),+ (+ "pipeline",+ models.CharField(+ choices=posthog.models.event_filter_config.ingestion_pipeline_choices,+ max_length=32,+ ),+ ),+ ("drop_all_events", models.BooleanField(default=False)),+ ("created_at", models.DateTimeField(auto_now_add=True)),+ ("updated_at", models.DateTimeField(auto_now=True)),+ (+ "created_by",+ models.ForeignKey(+ blank=True,+ db_constraint=False,+ null=True,+ on_delete=django.db.models.deletion.SET_NULL,+ to=settings.AUTH_USER_MODEL,+ ),+ ),+ (+ "team",+ models.ForeignKey(+ db_constraint=False,+ db_index=False,+ on_delete=django.db.models.deletion.CASCADE,+ to="posthog.team",+ ),+ ),+ ],+ options={+ "constraints": [+ models.UniqueConstraint(+ fields=("team", "pipeline"),+ name="posthog_unique_event_filter_pipeline_override",+ )+ ],+ "default_manager_name": "all_teams",+ },+ managers=[+ ("all_teams", django.db.models.manager.Manager()),+ ],+ ),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex 9ef40db59f0b..295058da0cb4 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1412_drop_retired_desktop_file_system_tables+1413_event_filter_pipeline_overridediff --git a/posthog/models/__init__.py b/posthog/models/__init__.pyindex 20586678410f..a043052fcc09 100644--- a/posthog/models/__init__.py+++ b/posthog/models/__init__.py@@ -23,7 +23,7 @@ from .event.event import Eventfrom .event_buffer import EventBuffer# TODO: remove noqa once the event filters API imports from posthog.models-from .event_filter_config import EventFilterConfig # noqa: F401+from .event_filter_config import EventFilterConfig, EventFilterPipelineOverride # noqa: F401from products.event_definitions.backend.models import EventDefinitionfrom products.event_definitions.backend.models import EventPropertyfrom .file_system.file_system import FileSystemdiff --git a/posthog/models/event_filter_config.py b/posthog/models/event_filter_config.pyindex 6de4410bd80d..734818380b04 100644--- a/posthog/models/event_filter_config.py+++ b/posthog/models/event_filter_config.py@@ -2,8 +2,10 @@ from django.conf import settingsfrom django.core.exceptions import ValidationErrorfrom django.db import models+from posthog.models.event_ingestion_restriction_config import IngestionPipeline+from posthog.models.scoping.manager import EnvironmentScopedManagerfrom posthog.models.team.team import Team-from posthog.models.utils import UUIDTModel+from posthog.models.utils import UUIDModel, UUIDTModelALLOWED_FIELDS = {"event_name", "distinct_id"}ALLOWED_OPERATORS = {"exact", "contains"}@@ -81,6 +83,45 @@ class EventFilterConfig(UUIDTModel):super().save(*args, **kwargs)+# nosemgrep: tuple-return-prefer-dataclass -- Django's `choices` contract is (value, label) pairs.+def ingestion_pipeline_choices() -> list[tuple[str, str]]:+ return [(pipeline.value, pipeline.value) for pipeline in IngestionPipeline]+++class EventFilterPipelineOverride(UUIDModel):+ """+ Per-environment, per-pipeline override of normal ingestion. A team without a row ingests+ normally, so a row is written only when the team first changes a pipeline.+ """++ # Ingestion matches a row by the event's own team_id, so rows are never moved to the parent team.+ all_teams = models.Manager()+ objects = EnvironmentScopedManager()++ # No standalone index: the (team, pipeline) unique constraint already leads on team_id.+ team = models.ForeignKey(Team, on_delete=models.CASCADE, db_constraint=False, db_index=False)+ pipeline = models.CharField(max_length=32, choices=ingestion_pipeline_choices)+ drop_all_events = models.BooleanField(default=False)+ created_at = models.DateTimeField(auto_now_add=True)+ updated_at = models.DateTimeField(auto_now=True)+ created_by = models.ForeignKey(+ settings.AUTH_USER_MODEL,+ on_delete=models.SET_NULL,+ null=True,+ blank=True,+ db_constraint=False,+ )++ class Meta:+ default_manager_name = "all_teams"+ constraints = [+ models.UniqueConstraint(fields=["team", "pipeline"], name="posthog_unique_event_filter_pipeline_override"),+ ]++ def __str__(self) -> str:+ return f"EventFilterPipelineOverride(team={self.team_id}, pipeline={self.pipeline}, drop_all_events={self.drop_all_events})"++def prune_filter_tree(node: dict) -> dict | None:"""Remove empty groups and collapse single-child groups, keeping an and/or