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(cdp): reject method calls on values in input templates (#115231)

Meikel Ratzd0e38b451867
diff --git a/posthog/cdp/test/test_validation.py b/posthog/cdp/test/test_validation.py
index ce548ccd55fa..6c874e4853e0 100644
--- a/posthog/cdp/test/test_validation.py
+++ b/posthog/cdp/test/test_validation.py
@@ -1197,6 +1197,11 @@ class TestHogFunctionValidation(ClickhouseTestMixin, APIBaseTest, QueryMatchingT
("wrong_argument_count", "{lower()}", "lower needs at least 1 argument(s), got 0"),
("core_async_function", "{fetch('https://example.com')}", "fetch is not a function"),
("product_async_function", "{postHogGetTicket('1')}", "postHogGetTicket is not a function"),
+ (
+ "method_call_on_a_value",
+ "{person.properties.email.isNotNull() ? person.properties.email : 'none'}",
+ "person.properties.email.isNotNull is a value, not a function",
+ ),
]
)
def test_destination_templates_refuse_calls_the_node_vm_cannot_make(self, _name, template, message):
diff --git a/posthog/cdp/validation.py b/posthog/cdp/validation.py
index c7179825b626..aef7a2de8d84 100644
--- a/posthog/cdp/validation.py
+++ b/posthog/cdp/validation.py
@@ -360,6 +360,16 @@ class TemplateGlobalsValidator(TraversingVisitor):
elif maximum is not None and count > maximum:
self.invalid_calls.append(f"{node.name} takes at most {maximum} argument(s), got {count}")
+ def visit_expr_call(self, node: ast.ExprCall) -> None:
+ super().visit_expr_call(node)
+ # `person.properties.email.isNotNull()` compiles to a call on the value at that path. Globals
+ # hold event data, never a function, so the VM refuses the call on every event.
+ if isinstance(node.expr, ast.Field) and node.expr.chain and str(node.expr.chain[0]) not in self._declared:
+ path = ".".join(str(part) for part in node.expr.chain)
+ self.invalid_calls.append(
+ f"{path} is a value, not a function. Write the function name first, as in isNotNull(person.properties.email)"
+ )
+
class DeclaredNamesCollector(TraversingVisitor):
"""Collect every identifier a hog program declares (variables, functions, params,