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.

test(hogql): run parser memory-leak matrix on rust-py only (the production backend) (#87204)

Paul D'Ambra0e1147aa5473
diff --git a/posthog/hogql/test/_test_parser.py b/posthog/hogql/test/_test_parser.py
index ecc17e89304b..f278f8e8e5bb 100644
--- a/posthog/hogql/test/_test_parser.py
+++ b/posthog/hogql/test/_test_parser.py
@@ -93,8 +93,13 @@ def _snapshot_key(src: str) -> str:
return f"{safe}-{digest}" if safe else digest
-def parser_test_factory(backend: HogQLParserBackend):
- base_classes = (MemoryLeakTestMixin, BaseTest)
+def parser_test_factory(backend: HogQLParserBackend, leak_check: bool = True):
+ # 102 re-parses per test to measure leaks is expensive at this suite's scale.
+ # The backends are separate parser implementations, so a leak is per-backend:
+ # keep the matrix on rust-py only, the production primary (PyO3-built objects
+ # are also the most binding-leak-prone path). cpp-json and rust-json run once
+ # per test — the shared snapshot still proves parity on all three.
+ base_classes = (MemoryLeakTestMixin, BaseTest) if leak_check else (BaseTest,)
class TestParser(*base_classes): # type: ignore
MEMORY_INCREASE_PER_PARSE_LIMIT_B = 10_000
@@ -124,10 +129,10 @@ def parser_test_factory(backend: HogQLParserBackend):
kwargs: dict[str, Any] = {"backend": backend}
if placeholders is not None:
kwargs["placeholders"] = placeholders
- # Parse on every rerun so the leak mixin still exercises the parser 102x and a real
- # per-parse leak is caught. Only COMPARE on the first run: syrupy / pretty_dataclasses
- # allocate per call, so comparing on every rerun would trip the leak check with
- # test-machinery growth that isn't a parser leak.
+ # Leak-checking backends parse on every mixin rerun so a real per-parse leak is
+ # caught. Only COMPARE on the first run: syrupy / pretty_dataclasses allocate per
+ # call, so comparing on every rerun would trip the leak check with test-machinery
+ # growth that isn't a parser leak.
parsed = parse_fn(src, **kwargs)
if getattr(self, "_memory_leak_run_index", 0) != 0:
return
diff --git a/posthog/hogql/test/test_parser_cpp_json.py b/posthog/hogql/test/test_parser_cpp_json.py
index 59ac83e88849..39528062deb6 100644
--- a/posthog/hogql/test/test_parser_cpp_json.py
+++ b/posthog/hogql/test/test_parser_cpp_json.py
@@ -9,7 +9,7 @@ from posthog.hogql.parser import parse_program
from ._test_parser import parser_test_factory
-class TestParserCppJson(parser_test_factory("cpp-json")): # type: ignore
+class TestParserCppJson(parser_test_factory("cpp-json", leak_check=False)): # type: ignore
def test_empty(self):
# this test only exists to make pycharm recognise this class as a test class
# the actual tests are in the parent class
diff --git a/posthog/hogql/test/test_parser_rust_json.py b/posthog/hogql/test/test_parser_rust_json.py
index 2da6943da3d9..6e4a396d66bf 100644
--- a/posthog/hogql/test/test_parser_rust_json.py
+++ b/posthog/hogql/test/test_parser_rust_json.py
@@ -8,7 +8,7 @@ the `rust-json` backend into that suite.
from ._test_parser import parser_test_factory
-class TestParserRustJson(parser_test_factory("rust-json")): # type: ignore
+class TestParserRustJson(parser_test_factory("rust-json", leak_check=False)): # type: ignore
def test_empty(self):
# this test only exists to make pycharm recognise this class as a test class
# the actual tests are in the parent class