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.

chore(tests): clear leaked log context in the stable chunks log test (#121781)

Felipe Rosa de Almeida9914ea561e8a
diff --git a/posthog/test/test_stable_chunks.py b/posthog/test/test_stable_chunks.py
index a52875e82cc4..cad69befa0d5 100644
--- a/posthog/test/test_stable_chunks.py
+++ b/posthog/test/test_stable_chunks.py
@@ -10,6 +10,7 @@ from django.contrib.sessions.middleware import SessionMiddleware
from django.http import HttpRequest, HttpResponse
from django.test import RequestFactory, SimpleTestCase, override_settings
+import structlog
from parameterized import parameterized
from prometheus_client import REGISTRY
from structlog.testing import capture_logs
@@ -146,6 +147,8 @@ class TestStableChunks(SimpleTestCase):
"?stable_chunks=fallback&stable_chunks_unmapped=@c/Abc123"
)
request.user = AnonymousUser()
+ # The structlog context is thread-local, so an earlier test's `bind()` on this worker would leak into the event.
+ structlog.get_logger().new()
with capture_logs() as logs:
stable_chunks_choice(request, None)