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.

fix(funnels): enforce lower bounds in ValidateFunnelExclusions (#121857)

Sam Pennington98166e6650cc
diff --git a/products/product_analytics/backend/hogql_queries/funnels/funnel_validation_rules.py b/products/product_analytics/backend/hogql_queries/funnels/funnel_validation_rules.py
index c1e15fdcce8f..24168bfc307f 100644
--- a/products/product_analytics/backend/hogql_queries/funnels/funnel_validation_rules.py
+++ b/products/product_analytics/backend/hogql_queries/funnels/funnel_validation_rules.py
@@ -113,6 +113,12 @@ class ValidateFunnelExclusions:
code=self.code,
)
+ if exclusion.funnelFromStep < 0:
+ raise ValidationError(
+ "Exclusion event range is invalid. Start of range cannot be negative.",
+ code=self.code,
+ )
+
if exclusion.funnelFromStep >= len(series) - 1:
raise ValidationError(
"Exclusion event range is invalid. Start of range is greater than number of steps.",
diff --git a/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_validation_rules.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_validation_rules.py
index 9d580e23604e..83fd7443505e 100644
--- a/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_validation_rules.py
+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_validation_rules.py
@@ -109,6 +109,11 @@ class TestFunnelValidationRules(BaseTest):
FunnelExclusionEventsNode(event="exclude", funnelFromStep=0, funnelToStep=3),
"Exclusion event range is invalid. End of range is greater than number of steps.",
),
+ (
+ "start_step_negative",
+ FunnelExclusionEventsNode(event="exclude", funnelFromStep=-1, funnelToStep=1),
+ "Exclusion event range is invalid. Start of range cannot be negative.",
+ ),
]
)
def test_validates_funnel_exclusion_ranges(self, _name, exclusion, expected_error):