: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-imports): retry a transient db drop in the byte-bounded flag gate (#94578)
Tom Owersa12527e1426f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.pyindex 530083eeff63..4cc8b1e56eb6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.py@@ -2,6 +2,7 @@ import posthoganalyticsfrom posthog.exceptions_capture import capture_exceptionfrom posthog.models.team.team import Team+from posthog.temporal.common.utils import retry_on_db_connection_dropBYTE_BOUNDED_EXTRACTION_FLAG = "warehouse-byte-bounded-extraction"@@ -17,7 +18,7 @@ def is_byte_bounded_extraction_enabled(team_id: int, source_type: str) -> bool:Fails closed: any error means "off", which keeps the row-count batching."""try:- team = Team.objects.only("uuid", "organization_id").get(id=team_id)+ team = retry_on_db_connection_drop(lambda: Team.objects.only("uuid", "organization_id").get(id=team_id))except Team.DoesNotExist:return Falseexcept Exception as e:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.pyindex 3fe86564be91..94a8c33d30e6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.py@@ -1,5 +1,7 @@import pytest-from unittest.mock import patch+from unittest.mock import MagicMock, patch++from django.db import OperationalErrorfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.byte_bounded_extraction_flag import (is_byte_bounded_extraction_enabled,@@ -21,6 +23,17 @@ class TestByteBoundedExtractionFlagFailsClosed:def test_missing_team_returns_false(self):assert is_byte_bounded_extraction_enabled(999999999, "MySQL") is False+ def test_transient_db_connection_drop_is_retried(self):+ with (+ patch(f"{_MODULE}.Team") as team_cls,+ patch(f"{_MODULE}.posthoganalytics.feature_enabled", return_value=True),+ ):+ team_cls.objects.only.return_value.get.side_effect = [+ OperationalError("[Errno -2] Name or service not known"),+ MagicMock(),+ ]+ assert is_byte_bounded_extraction_enabled(1, "MySQL") is True+def test_source_type_reaches_the_flag_for_per_driver_targeting(self):with (patch(f"{_MODULE}.Team") as team_cls,