: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(billing): read DUCKGRES_PG_URL from env instead of settings (#65171)
Abhischek31cca34d8399
diff --git a/ee/billing/salesforce_enrichment/duckgres_client.py b/ee/billing/salesforce_enrichment/duckgres_client.pyindex 3b296677048a..6d4bb3374dd6 100644--- a/ee/billing/salesforce_enrichment/duckgres_client.py+++ b/ee/billing/salesforce_enrichment/duckgres_client.py@@ -1,11 +1,10 @@"""Postgres client for the duckgres DWH (ducklake proxy)."""+import osfrom collections.abc import Iteratorfrom contextlib import contextmanagerfrom typing import cast-from django.conf import settings-import psycopgfrom psycopg import sqlfrom psycopg.rows import DictRow, dict_row@@ -25,11 +24,12 @@ def duckgres_cursor() -> Iterator[psycopg.Cursor[DictRow]]:A per-session statement timeout is set so a runaway analytics query cannotpin the worker — the caller is expected to paginate large result sets."""- if not settings.DUCKGRES_PG_URL:+ pg_url = os.environ.get("DUCKGRES_PG_URL")+ if not pg_url:raise DuckgresNotConfiguredError("DUCKGRES_PG_URL is not set")with psycopg.connect(- settings.DUCKGRES_PG_URL,+ pg_url,connect_timeout=_CONNECT_TIMEOUT_SECONDS,row_factory=dict_row,) as conn:diff --git a/ee/billing/test/test_stripe_signals.py b/ee/billing/test/test_stripe_signals.pyindex a80bce88ffc4..56f822dbff94 100644--- a/ee/billing/test/test_stripe_signals.py+++ b/ee/billing/test/test_stripe_signals.py@@ -1,11 +1,10 @@+import osimport datetime as dtfrom unittest import TestCasefrom unittest.mock import MagicMock, patch-from django.conf import settings--from ee.billing.salesforce_enrichment.duckgres_client import DuckgresNotConfiguredError+from ee.billing.salesforce_enrichment.duckgres_client import DuckgresNotConfiguredError, duckgres_cursorfrom ee.billing.salesforce_enrichment.stripe_signals import _FETCH_QUERY, StripeSignals, fetch_stripe_signals@@ -79,12 +78,19 @@ class TestStripeSignalsDataClass(TestCase):class TestFetchStripeSignals(TestCase):- @patch.object(settings, "DUCKGRES_PG_URL", None, create=True)+ @patch.dict(os.environ, {"DUCKGRES_PG_URL": ""})def test_raises_when_not_configured(self):with self.assertRaises(DuckgresNotConfiguredError):fetch_stripe_signals(limit=100)- @patch.object(settings, "DUCKGRES_PG_URL", "postgresql://user:pass@host/db", create=True)+ @patch.dict(os.environ, {"DUCKGRES_PG_URL": "postgresql://user:pass@host/db"})+ @patch("ee.billing.salesforce_enrichment.duckgres_client.psycopg.connect")+ def test_duckgres_cursor_connects_with_env_url(self, mock_connect):+ with duckgres_cursor():+ pass++ assert mock_connect.call_args[0][0] == "postgresql://user:pass@host/db"+@patch("ee.billing.salesforce_enrichment.stripe_signals.duckgres_cursor")def test_full_backfill_passes_none_cursor(self, mock_cursor_ctx):mock_cursor = MagicMock()@@ -102,7 +108,6 @@ class TestFetchStripeSignals(TestCase):assert executed_params["cursor_org_id"] is Noneassert executed_params["limit"] == 500- @patch.object(settings, "DUCKGRES_PG_URL", "postgresql://user:pass@host/db", create=True)@patch("ee.billing.salesforce_enrichment.stripe_signals.duckgres_cursor")def test_keyset_cursor_passed_through(self, mock_cursor_ctx):mock_cursor = MagicMock()@@ -116,7 +121,6 @@ class TestFetchStripeSignals(TestCase):assert executed_params["cursor_ts"] == cursor_tsassert executed_params["cursor_org_id"] == "org-42"- @patch.object(settings, "DUCKGRES_PG_URL", "postgresql://user:pass@host/db", create=True)@patch("ee.billing.salesforce_enrichment.stripe_signals.duckgres_cursor")def test_returns_empty_list_when_no_rows(self, mock_cursor_ctx):mock_cursor = MagicMock()@@ -125,7 +129,6 @@ class TestFetchStripeSignals(TestCase):assert fetch_stripe_signals(limit=100) == []- @patch.object(settings, "DUCKGRES_PG_URL", "postgresql://user:pass@host/db", create=True)@patch("ee.billing.salesforce_enrichment.stripe_signals.duckgres_cursor")def test_maps_all_address_fields(self, mock_cursor_ctx):mock_cursor = MagicMock()