: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(warehouse): send Deepgram-accepted start filter for requests log (#87532)
posthog[bot]7b22e6694527
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/deepgram.py b/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/deepgram.pyindex 431324541bb6..b72160b69e6b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/deepgram.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/deepgram.py@@ -97,14 +97,17 @@ class DeepgramResumeConfig:def _format_start_value(value: Any) -> str:"""Format an incremental cursor value for Deepgram's `start` filter.- Deepgram accepts YYYY-MM-DD or ISO 8601; we send full ISO 8601 with a Z suffix. Future-dated- cursors are capped at now so we never build a start-in-the-future filter (harmless but pointless).+ The requests log accepts only YYYY-MM-DD, YYYY-MM-DDTHH:MM:SS, or YYYY-MM-DDTHH:MM:SS+HH:MM.+ It rejects fractional seconds and a `Z` suffix with HTTP 400, so a datetime cursor is emitted as+ whole-second ISO 8601 with a numeric UTC offset. The seconds are floored, so the boundary second+ is re-fetched (the merge dedupes on the composite primary key) rather than skipped. Future-dated+ cursors are capped at now so we never build a start-in-the-future filter."""now = datetime.now(UTC)if isinstance(value, datetime):aware = value if value.tzinfo is not None else value.replace(tzinfo=UTC)aware = now if aware > now else aware- return aware.astimezone(UTC).strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"+ return aware.astimezone(UTC).replace(microsecond=0).isoformat()if isinstance(value, date):capped = now.date() if value > now.date() else valuereturn capped.isoformat()diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/source.pyindex 58a1cf6d63d4..9d07ea4c76b1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/source.py@@ -81,6 +81,9 @@ You can create an API key in your [Deepgram Console](https://console.deepgram.coreturn {"401 Client Error: Unauthorized for url: https://api.deepgram.com": "Your Deepgram API key is invalid or has been revoked. Create a new key in your Deepgram Console, then reconnect.","403 Client Error: Forbidden for url: https://api.deepgram.com": "Your Deepgram API key is missing the scope needed to sync this data. Grant a read-capable scope in your Deepgram Console, then reconnect.",+ # Deepgram returns 400 for a request it cannot accept. The same request always fails the+ # same way, so retrying cannot fix it. Fail the sync and point the user to support.+ "400 Client Error: Bad Request for url: https://api.deepgram.com": "Deepgram rejected this sync request with a 400 Bad Request, so the sync cannot continue. Contact PostHog support with your Deepgram source details so we can investigate.",}def get_schemas(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/tests/test_deepgram.py b/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/tests/test_deepgram.pyindex 41c8ed3554a5..74565e0b70f0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/tests/test_deepgram.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/tests/test_deepgram.py@@ -77,22 +77,20 @@ def _source(endpoint: str, manager: mock.MagicMock, **kwargs: Any):class TestFormatStartValue:@parameterized.expand([- ("utc_datetime", datetime(2026, 3, 4, 2, 58, 14, tzinfo=UTC), "2026-03-04T02:58:14.000Z"),- ("naive_datetime", datetime(2026, 3, 4, 2, 58, 14), "2026-03-04T02:58:14.000Z"),+ ("utc_datetime", datetime(2026, 3, 4, 2, 58, 14, tzinfo=UTC), "2026-03-04T02:58:14+00:00"),+ ("naive_datetime", datetime(2026, 3, 4, 2, 58, 14), "2026-03-04T02:58:14+00:00"),+ # Deepgram rejects fractional seconds, so a cursor with microseconds is floored to the second.+ ("subsecond_datetime", datetime(2026, 3, 4, 2, 58, 14, 987654, tzinfo=UTC), "2026-03-04T02:58:14+00:00"),("date_value", date(2026, 3, 4), "2026-03-04"),])def test_format(self, _name: str, value: Any, expected: str) -> None:assert _format_start_value(value) == expected- def test_no_plus_zero_offset(self) -> None:- # A +00:00 offset (isoformat default) is not the ISO shape we send; assert we emit the Z form.- assert "+00:00" not in _format_start_value(datetime(2026, 3, 4, 2, 58, 14, tzinfo=UTC))-@freeze_time("2026-06-15T12:00:00Z")def test_future_datetime_clamped_to_now(self) -> None:# Asking for requests created after "now" is pointless; cap it so we don't skip the window.- assert _format_start_value(datetime(2027, 1, 1, tzinfo=UTC)) == "2026-06-15T12:00:00.000Z"+ assert _format_start_value(datetime(2027, 1, 1, tzinfo=UTC)) == "2026-06-15T12:00:00+00:00"class TestChildMap:@@ -280,7 +278,7 @@ class TestRequestsIncremental:))- assert snapshots[-1][1]["start"] == "2026-03-04T02:58:14.000Z"+ assert snapshots[-1][1]["start"] == "2026-03-04T02:58:14+00:00"assert snapshots[-1][1]["limit"] == deepgram_mod.REQUESTS_PAGE_SIZE# The parent project enumeration carries no incremental filter.assert "start" not in snapshots[0][1]diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/tests/test_deepgram_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/tests/test_deepgram_source.pyindex acbf45d99095..12898e32f23e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/tests/test_deepgram_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/deepgram/tests/test_deepgram_source.py@@ -85,10 +85,15 @@ class TestDeepgramSourceClass:ok, _error = self.source.validate_credentials(DeepgramSourceConfig(api_key="k"), team_id=1)assert ok is expected- def test_non_retryable_errors_cover_auth(self) -> None:+ def test_non_retryable_errors_cover_auth_and_bad_request(self) -> None:errors = self.source.get_non_retryable_errors()assert any("401" in key for key in errors)assert any("403" in key for key in errors)+ # A 400 is a deterministic client error; it must fail the sync with a friendly message rather+ # than retry and store the raw "400 Client Error: Bad Request".+ bad_request = [message for key, message in errors.items() if "400 Client Error: Bad Request" in key]+ assert len(bad_request) == 1+ assert bad_request[0]def test_resumable_manager_bound_to_resume_config(self) -> None:manager = self.source.get_resumable_source_manager(_inputs())