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.

fix(gong): treat empty calls window 404 as no data (#67264)

Tom Owers12b814066df9
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gong/gong.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gong/gong.py
index f2d066a511d0..cc373cf4efd6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gong/gong.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gong/gong.py
@@ -128,6 +128,12 @@ def get_rows(
if response.status_code == 429 or response.status_code >= 500:
raise GongRetryableError(f"Gong API error (retryable): status={response.status_code}, url={url}")
+ # Gong's `/v2/calls` answers a date window with no processed calls using a 404
+ # ("No calls found corresponding to the provided filters") rather than an empty 200.
+ # Treat it as an empty page so the sync skips the window instead of failing.
+ if config.uses_date_window and response.status_code == 404 and "no calls" in response.text.lower():
+ return {}
+
if not response.ok:
logger.error(f"Gong API error: status={response.status_code}, body={response.text}, url={url}")
response.raise_for_status()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gong/tests/test_gong.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gong/tests/test_gong.py
index 3cb9e7329013..4f5023e806ba 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gong/tests/test_gong.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gong/tests/test_gong.py
@@ -3,6 +3,7 @@ from datetime import UTC, date, datetime, timedelta
from typing import Any
from urllib.parse import unquote
+import pytest
from unittest import mock
from parameterized import parameterized
@@ -239,6 +240,51 @@ class TestWindowedCalls:
assert batches == [[{"id": "c1"}], [{"id": "c2"}]]
assert "cursor=page2" in session.requested_urls[1]
+ @parameterized.expand(
+ [
+ # Gong signals an empty date window with a 404; the sync skips it and continues.
+ (
+ "no_calls_body_skips_window",
+ '{"errors":["No calls found corresponding to the provided filters"]}',
+ False,
+ ),
+ # A 404 for any other reason must still surface rather than be swallowed.
+ ("unrelated_404_raises", '{"errors":["Not Found"]}', True),
+ ]
+ )
+ def test_404_handling(self, _name: str, body: str, should_raise: bool) -> None:
+ last_value = datetime.now(UTC) - timedelta(days=100)
+ responses = [
+ _FakeResponse(status_code=404, text=body),
+ _FakeResponse(json_data={"calls": [{"id": "c1"}]}),
+ ]
+ session = _FakeSession(responses)
+ manager = _FakeResumableManager()
+
+ with mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.gong.gong.make_tracked_session",
+ return_value=session,
+ ):
+ rows = get_rows(
+ "key",
+ "secret",
+ "calls",
+ mock.MagicMock(),
+ manager,
+ should_use_incremental_field=True,
+ db_incremental_field_last_value=last_value,
+ )
+ if should_raise:
+ with pytest.raises(Exception):
+ list(rows)
+ return
+ batches = list(rows)
+
+ # The empty window yields nothing but does not abort the sync; both windows run.
+ assert batches == [[{"id": "c1"}]]
+ assert len(session.requested_urls) == 2
+ assert len(manager.saved_states) == 2
+
def test_resume_uses_saved_window_start(self) -> None:
last_value = datetime.now(UTC) - timedelta(days=80)
resume_start = datetime.now(UTC) - timedelta(days=10)