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(data-imports): treat Northpass empty-collection 404s as empty pages (#78447)

Tom Owers297d492509c7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/northpass_lms/northpass_lms.py b/products/warehouse_sources/backend/temporal/data_imports/sources/northpass_lms/northpass_lms.py
index 7f95595937e4..807d7353dfbd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/northpass_lms/northpass_lms.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/northpass_lms/northpass_lms.py
@@ -116,7 +116,10 @@ def _top_level_source(
) -> Resource:
rest_config: RESTAPIConfig = {
"client": _client_config(api_key),
- "resource_defaults": {},
+ # A collection with no rows 404s instead of returning `data: []` (seen on
+ # /learning-paths); retrying can't produce rows, so treat it like the empty-body
+ # case above and let the resource yield nothing rather than failing the sync.
+ "resource_defaults": {"endpoint": {"response_actions": [{"status_code": 404, "action": "ignore"}]}},
"resources": [
{
"name": endpoint,
@@ -170,7 +173,10 @@ def _fan_out_source(
rest_config: RESTAPIConfig = {
"client": _client_config(api_key),
- "resource_defaults": {},
+ # Same "empty collection 404s instead of `data: []`" case as the top-level source: the
+ # parent enumeration below inherits this so an account with no parent rows fans out over
+ # zero parents instead of failing the sync outright.
+ "resource_defaults": {"endpoint": {"response_actions": [{"status_code": 404, "action": "ignore"}]}},
"resources": [
{
"name": parent_name,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/northpass_lms/tests/test_northpass_lms.py b/products/warehouse_sources/backend/temporal/data_imports/sources/northpass_lms/tests/test_northpass_lms.py
index e1feef738c85..8d430a9209da 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/northpass_lms/tests/test_northpass_lms.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/northpass_lms/tests/test_northpass_lms.py
@@ -184,6 +184,18 @@ class TestTopLevelPagination:
assert off_host_url not in sent
assert sent == [COURSES_P1]
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_treats_404_on_first_page_as_empty_collection(self, mock_make_session):
+ # An account with no rows in a collection 404s instead of returning `data: []` (seen on
+ # /learning-paths). This must not fail the sync -- it's the same "no data" outcome as an
+ # empty body, not a retryable or fatal error.
+ pages = {COURSES_P1: _resp({"errors": []}, status=404)}
+ _wire(mock_make_session, pages)
+
+ rows = _rows("courses", _make_manager())
+
+ assert rows == []
+
class TestFanOut:
def _parent_and_children(self) -> dict[str, Any]:
@@ -258,6 +270,17 @@ class TestFanOut:
with pytest.raises(requests.HTTPError):
_rows("course_enrollments", _make_manager())
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_treats_404_on_parent_enumeration_as_empty(self, mock_make_session):
+ # The parent list itself (not a per-parent child page) 404s when the account has no
+ # parent rows. Fanning out over zero parents must yield zero rows, not crash the sync.
+ pages = {"https://api.northpass.com/v2/courses?limit=100": _resp({"errors": []}, status=404)}
+ _wire(mock_make_session, pages)
+
+ rows = _rows("course_enrollments", _make_manager())
+
+ assert rows == []
+
class TestNorthpassSource:
@parameterized.expand(