: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
fix(data-warehouse): keep the database URL out of the partition job's frame locals (#94342)
Jovan Sakovicc9ba26d3c0a2
diff --git a/posthog/temporal/tests/warehouse_sources_queue_partition_management/test_activities.py b/posthog/temporal/tests/warehouse_sources_queue_partition_management/test_activities.pyindex 6cca6bc78869..f45d5dbb46ed 100644--- a/posthog/temporal/tests/warehouse_sources_queue_partition_management/test_activities.py+++ b/posthog/temporal/tests/warehouse_sources_queue_partition_management/test_activities.py@@ -4,11 +4,14 @@ from __future__ import annotationsfrom contextlib import contextmanagerfrom datetime import date+from types import TracebackTypefrom typing import Any, Literalimport pytestfrom unittest.mock import MagicMock, call, patch+import psycopg+from posthog.temporal.warehouse_sources_queue_partition_management import activities as activities_modulefrom posthog.temporal.warehouse_sources_queue_partition_management.activities import (RETENTION_STRANDED_ERROR,@@ -519,3 +522,37 @@ async def test_activity_logs_s3_deleted_count(activity_environment) -> None:]assert len(completion_calls) == 1assert completion_calls[0].kwargs["s3_deleted_count"] == 2+++def _connect_refused(*args: Any, **kwargs: Any) -> None:+ del args, kwargs+ raise psycopg.OperationalError("connection refused")+++def _frames_holding(tb: TracebackType | None, needle: str) -> list[str]:+ hits: list[str] = []+ while tb is not None:+ if needle in repr(tb.tb_frame.f_locals):+ hits.append(tb.tb_frame.f_code.co_qualname)+ tb = tb.tb_next+ return hits+++_SECRET = "invented-secret"+++async def test_connect_failure_keeps_database_url_out_of_traceback_locals() -> None:+ with (+ patch.object(+ activities_module.settings,+ "WAREHOUSE_SOURCES_DATABASE_URL",+ f"postgres://alice:{_SECRET}@db.example.com/app",+ ),+ patch.object(activities_module.psycopg.Connection, "connect", _connect_refused),+ pytest.raises(psycopg.OperationalError) as exc_info,+ ):+ await manage_warehouse_sources_queue_partitions()++ hits = _frames_holding(exc_info.value.__traceback__, _SECRET)+ assert hits == []diff --git a/posthog/temporal/warehouse_sources_queue_partition_management/activities.py b/posthog/temporal/warehouse_sources_queue_partition_management/activities.pyindex e26319c9fb8c..10b63a9abe2a 100644--- a/posthog/temporal/warehouse_sources_queue_partition_management/activities.py+++ b/posthog/temporal/warehouse_sources_queue_partition_management/activities.py@@ -41,12 +41,11 @@ class PartitionResult:@temporalio.activity.defnasync def manage_warehouse_sources_queue_partitions() -> dict:- database_url: str = settings.WAREHOUSE_SOURCES_DATABASE_URLensured: list[str] = []dropped: list[str] = []errors: list[str] = []- with psycopg.Connection.connect(database_url, autocommit=True) as conn:+ with psycopg.Connection.connect(settings.WAREHOUSE_SOURCES_DATABASE_URL, autocommit=True) as conn:today = datetime.now(UTC).date()for table in PARTITIONED_TABLES: