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-warehouse): skip plan-gated pagerduty tables instead of failing (#104181)

Tom Owers0c4b42f2905e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/pagerduty.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/pagerduty.py
index 2446ccf339bc..88d9027cb670 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/pagerduty.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/pagerduty.py
@@ -1,9 +1,12 @@
import dataclasses
+from collections.abc import Iterator
from datetime import UTC, date, datetime
from typing import Any, Optional
from urllib.parse import urlencode
from requests import Request, Response
+from requests.exceptions import HTTPError
+from structlog.types import FilteringBoundLogger
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (
@@ -30,6 +33,11 @@ PAGE_SIZE = 100
# on very large accounts.
MAX_OFFSET = 10_000
+# The statuses PagerDuty answers for a feature the account's plan does not include: 402 with error
+# code 2014 ("required abilities are unavailable") for /teams, and 404 for /priorities. Each gated
+# endpoint's `PagerDutyEndpointConfig.plan_gated_status` says which one applies to it — the other
+# status on that same endpoint is a genuine failure and must still raise.
+
@dataclasses.dataclass
class PagerDutyResumeConfig:
@@ -130,6 +138,24 @@ def _non_secret_headers() -> dict[str, str]:
}
+def _skip_when_plan_gated(
+ items: Iterator[Any],
+ endpoint: str,
+ plan_gated_feature: str,
+ plan_gated_status: int,
+ logger: FilteringBoundLogger,
+) -> Iterator[Any]:
+ try:
+ yield from items
+ except HTTPError as err:
+ if err.response is None or err.response.status_code != plan_gated_status:
+ raise
+ logger.warning(
+ f"Your PagerDuty plan does not include {plan_gated_feature}, so the {endpoint} table synced no rows. "
+ "Turn off syncing for this table, or upgrade your PagerDuty plan."
+ )
+
+
def validate_credentials(api_token: str, endpoint: Optional[str] = None) -> tuple[bool, int, str | None]:
"""Probe PagerDuty with a cheap single-row request.
@@ -162,6 +188,7 @@ def pagerduty_source(
team_id: int,
job_id: str,
resumable_source_manager: ResumableSourceManager[PagerDutyResumeConfig],
+ logger: FilteringBoundLogger,
should_use_incremental_field: bool = False,
db_incremental_field_last_value: Optional[Any] = None,
) -> SourceResponse:
@@ -230,9 +257,18 @@ def pagerduty_source(
initial_paginator_state=initial_paginator_state,
)
+ plan_gated_feature = config.plan_gated_feature
+ plan_gated_status = config.plan_gated_status
+
+ def items() -> Iterator[Any]:
+ if plan_gated_feature is None or plan_gated_status is None:
+ yield from resource
+ return
+ yield from _skip_when_plan_gated(iter(resource), endpoint, plan_gated_feature, plan_gated_status, logger)
+
return SourceResponse(
name=endpoint,
- items=lambda: resource,
+ items=items,
primary_keys=[config.primary_key],
# We always request created_at ascending where a sort is available, and full-refresh endpoints
# replace wholesale, so ascending is correct everywhere.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/settings.py
index c906162f32a3..5a6d19b178b2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/settings.py
@@ -1,10 +1,12 @@
-from dataclasses import dataclass, field
+from dataclasses import field
from typing import Optional
+from posthog.dataclasses import frozen
+
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
-@dataclass
+@frozen
class PagerDutyEndpointConfig:
path: str # Path under the API base URL, e.g. "/incidents"
envelope_key: str # Key the list of objects is wrapped under in the response body
@@ -17,6 +19,15 @@ class PagerDutyEndpointConfig:
# ascending watermark. Endpoints without a controllable sort stay full-refresh so the
# cursor can't advance past unread rows.
supports_since: bool = False
+ # Names the PagerDuty feature an account needs before this endpoint answers at all, and the
+ # single HTTP status that endpoint answers with when the plan lacks it (402 with error code
+ # 2014, "required abilities are unavailable", or 404). The two fields are set together: a
+ # config with a feature but no status is a mistake, not "accept anything". Kept endpoint-
+ # specific rather than a shared {402, 404} set, because the other status is a genuine failure
+ # on that endpoint (e.g. a 404 on /teams is a real missing resource, not a plan gate) and must
+ # still raise instead of being swallowed as an empty table.
+ plan_gated_feature: Optional[str] = None
+ plan_gated_status: Optional[int] = None
_CREATED_AT_INCREMENTAL: list[IncrementalField] = [
@@ -61,6 +72,10 @@ PAGERDUTY_ENDPOINTS: dict[str, PagerDutyEndpointConfig] = {
"teams": PagerDutyEndpointConfig(
path="/teams",
envelope_key="teams",
+ # PagerDuty gates teams behind an account ability; accounts without it answer 402 with
+ # error code 2014 on every /teams request.
+ plan_gated_feature="teams",
+ plan_gated_status=402,
),
"escalation_policies": PagerDutyEndpointConfig(
path="/escalation_policies",
@@ -73,6 +88,11 @@ PAGERDUTY_ENDPOINTS: dict[str, PagerDutyEndpointConfig] = {
"priorities": PagerDutyEndpointConfig(
path="/priorities",
envelope_key="priorities",
+ # Incident priorities exist only on higher PagerDuty plans. The collection endpoint takes
+ # no path parameter, and an account that has the feature but no priority configured still
+ # answers 200 with an empty list, so a 404 here can only mean the plan lacks the feature.
+ plan_gated_feature="incident priorities",
+ plan_gated_status=404,
),
"vendors": PagerDutyEndpointConfig(
path="/vendors",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/source.py
index 231359be9a1f..13526b43be30 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/source.py
@@ -29,6 +29,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.pagerduty.
from products.warehouse_sources.backend.temporal.data_imports.sources.pagerduty.settings import (
ENDPOINTS,
INCREMENTAL_FIELDS,
+ PAGERDUTY_ENDPOINTS,
)
from products.warehouse_sources.backend.types import ExternalDataSourceType
@@ -108,6 +109,18 @@ You can create a read-only API key in your PagerDuty account under **Integration
if status == 403 and schema_name is None:
return True, None
+ # A plan-gated endpoint answers its declared status (402 for teams, 404 for priorities) for
+ # every account whose plan lacks the feature. The sync already skips that table with a
+ # warning, so the credentials are fine and the schema settings must stay reachable. Any
+ # other status on that same endpoint is a genuine failure and still falls through below.
+ endpoint_config = PAGERDUTY_ENDPOINTS.get(schema_name) if schema_name else None
+ if (
+ endpoint_config is not None
+ and endpoint_config.plan_gated_feature
+ and status == endpoint_config.plan_gated_status
+ ):
+ return True, None
+
return False, error
def get_non_retryable_errors(self) -> dict[str, str | None]:
@@ -131,6 +144,7 @@ You can create a read-only API key in your PagerDuty account under **Integration
team_id=inputs.team_id,
job_id=inputs.job_id,
resumable_source_manager=resumable_source_manager,
+ logger=inputs.logger,
should_use_incremental_field=inputs.should_use_incremental_field,
db_incremental_field_last_value=inputs.db_incremental_field_last_value
if inputs.should_use_incremental_field
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/tests/test_pagerduty.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/tests/test_pagerduty.py
index 133d4035e2e2..926e7b3ecb85 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/tests/test_pagerduty.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/tests/test_pagerduty.py
@@ -6,6 +6,7 @@ import pytest
from unittest import mock
from requests import Response
+from requests.exceptions import HTTPError
from products.warehouse_sources.backend.temporal.data_imports.sources.pagerduty.pagerduty import (
PAGE_SIZE,
@@ -36,11 +37,11 @@ def _response(items: Optional[list[dict[str, Any]]], *, more: bool = False, enve
return resp
-def _error_response(status_code: int) -> Response:
+def _error_response(status_code: int, *, path: str = "/incidents", body: Optional[dict[str, Any]] = None) -> Response:
resp = Response()
resp.status_code = status_code
- resp._content = json.dumps({"error": {"message": "boom"}}).encode()
- resp.url = "https://api.pagerduty.com/incidents"
+ resp._content = json.dumps(body if body is not None else {"error": {"message": "boom"}}).encode()
+ resp.url = f"https://api.pagerduty.com{path}"
return resp
@@ -110,7 +111,16 @@ class TestAuth:
session.prepare_request.side_effect = _prepare
session.send.side_effect = [_response([{"id": "1"}], more=False)]
- _rows(pagerduty_source("tok_abc", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager()))
+ _rows(
+ pagerduty_source(
+ "tok_abc",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
+ )
assert captured["auth"] == "Token token=tok_abc"
@@ -127,7 +137,14 @@ class TestPagination:
)
rows = _rows(
- pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ pagerduty_source(
+ "tok",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
)
assert [r["id"] for r in rows] == ["1", "2", "3"]
assert session.send.call_count == 2
@@ -143,7 +160,16 @@ class TestPagination:
],
)
- _rows(pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager()))
+ _rows(
+ pagerduty_source(
+ "tok",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
+ )
assert params[0]["offset"] == 0
assert params[0]["limit"] == PAGE_SIZE
assert params[1]["offset"] == PAGE_SIZE
@@ -162,7 +188,14 @@ class TestPagination:
)
rows = _rows(
- pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ pagerduty_source(
+ "tok",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
)
assert [r["id"] for r in rows] == ["1", "2"]
@@ -172,7 +205,14 @@ class TestPagination:
_wire(session, [_response([{"id": "1"}], more=False)])
rows = _rows(
- pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ pagerduty_source(
+ "tok",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
)
assert [r["id"] for r in rows] == ["1"]
assert session.send.call_count == 1
@@ -184,7 +224,14 @@ class TestPagination:
_wire(session, [_response([], more=True)])
rows = _rows(
- pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ pagerduty_source(
+ "tok",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
)
assert rows == []
assert session.send.call_count == 1
@@ -195,7 +242,14 @@ class TestPagination:
_wire(session, [_response(None, more=True)])
rows = _rows(
- pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ pagerduty_source(
+ "tok",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
)
assert rows == []
@@ -205,7 +259,14 @@ class TestPagination:
_wire(session, [_response([{"id": "svc_1"}], more=False, envelope="services")])
rows = _rows(
- pagerduty_source("tok", "services", team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ pagerduty_source(
+ "tok",
+ "services",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
)
assert [r["id"] for r in rows] == ["svc_1"]
@@ -225,7 +286,16 @@ class TestPagination:
# Always more=True — only the offset ceiling can stop it.
session.send.side_effect = [_response([{"id": str(i)}], more=True) for i in range(200)]
- _rows(pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager()))
+ _rows(
+ pagerduty_source(
+ "tok",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
+ )
assert offsets[0] == 0
assert offsets[-1] == 9900
assert 10000 not in offsets
@@ -238,7 +308,11 @@ class TestResume:
params = _wire(session, [_response([{"id": "x"}], more=False)])
manager = _make_manager(PagerDutyResumeConfig(offset=PAGE_SIZE))
- _rows(pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=manager))
+ _rows(
+ pagerduty_source(
+ "tok", "incidents", team_id=1, job_id="j", resumable_source_manager=manager, logger=mock.MagicMock()
+ )
+ )
assert params[0]["offset"] == PAGE_SIZE
@mock.patch(CLIENT_SESSION_PATCH)
@@ -253,7 +327,11 @@ class TestResume:
)
manager = _make_manager()
- _rows(pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=manager))
+ _rows(
+ pagerduty_source(
+ "tok", "incidents", team_id=1, job_id="j", resumable_source_manager=manager, logger=mock.MagicMock()
+ )
+ )
# Checkpoint saved once (next offset) after the first page; the final page (more=False) saves nothing.
saved = [c.args[0] for c in manager.save_state.call_args_list]
assert saved == [PagerDutyResumeConfig(offset=PAGE_SIZE)]
@@ -272,6 +350,7 @@ class TestIncremental:
team_id=1,
job_id="j",
resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
should_use_incremental_field=True,
db_incremental_field_last_value=datetime(2026, 1, 1, tzinfo=UTC),
)
@@ -291,6 +370,7 @@ class TestIncremental:
team_id=1,
job_id="j",
resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
should_use_incremental_field=True,
db_incremental_field_last_value=None,
)
@@ -303,7 +383,16 @@ class TestIncremental:
session = MockSession.return_value
params = _wire(session, [_response([{"id": "1"}], more=False)])
- _rows(pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager()))
+ _rows(
+ pagerduty_source(
+ "tok",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
+ )
assert params[0]["sort_by"] == "created_at:asc"
assert "since" not in params[0]
@@ -319,6 +408,7 @@ class TestIncremental:
team_id=1,
job_id="j",
resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
should_use_incremental_field=True,
db_incremental_field_last_value=datetime(2026, 1, 1, tzinfo=UTC),
)
@@ -335,7 +425,14 @@ class TestRetries:
_wire(session, [_error_response(429), _response([{"id": "1"}], more=False)])
rows = _rows(
- pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ pagerduty_source(
+ "tok",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
)
assert [r["id"] for r in rows] == ["1"]
assert session.send.call_count == 2
@@ -347,7 +444,14 @@ class TestRetries:
_wire(session, [_error_response(500), _response([{"id": "1"}], more=False)])
rows = _rows(
- pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ pagerduty_source(
+ "tok",
+ "incidents",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
)
assert [r["id"] for r in rows] == ["1"]
assert session.send.call_count == 2
@@ -396,7 +500,9 @@ class TestValidateCredentials:
class TestPagerDutySourceResponse:
def test_incidents_partitioned_on_created_at(self) -> None:
- response = pagerduty_source("tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ response = pagerduty_source(
+ "tok", "incidents", team_id=1, job_id="j", resumable_source_manager=_make_manager(), logger=mock.MagicMock()
+ )
assert response.primary_keys == ["id"]
assert response.partition_keys == ["created_at"]
assert response.partition_mode == "datetime"
@@ -404,14 +510,112 @@ class TestPagerDutySourceResponse:
assert response.sort_mode == "asc"
def test_unpartitioned_endpoint_has_no_partition_settings(self) -> None:
- response = pagerduty_source("tok", "users", team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ response = pagerduty_source(
+ "tok", "users", team_id=1, job_id="j", resumable_source_manager=_make_manager(), logger=mock.MagicMock()
+ )
assert response.primary_keys == ["id"]
assert response.partition_keys is None
assert response.partition_mode is None
@pytest.mark.parametrize("endpoint", list(PAGERDUTY_ENDPOINTS.keys()))
def test_every_endpoint_builds_a_response(self, endpoint: str) -> None:
- response = pagerduty_source("tok", endpoint, team_id=1, job_id="j", resumable_source_manager=_make_manager())
+ response = pagerduty_source(
+ "tok", endpoint, team_id=1, job_id="j", resumable_source_manager=_make_manager(), logger=mock.MagicMock()
+ )
assert response.name == endpoint
assert response.primary_keys == [PAGERDUTY_ENDPOINTS[endpoint].primary_key]
assert callable(response.items)
+
+
+class TestPlanGatedEndpoints:
+ @pytest.mark.parametrize(
+ "endpoint,status_code,body,feature",
+ [
+ # The statuses PagerDuty answers on an account whose plan lacks the feature. The 402
+ # body keeps PagerDuty's documented error code 2014, which the client appends to the
+ # raised message as "api error: code=2014".
+ ("teams", 402, {"error": {"code": 2014, "message": "Required abilities are unavailable"}}, "teams"),
+ ("priorities", 404, {"error": {"message": "Not Found"}}, "incident priorities"),
+ ],
+ )
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_plan_gated_endpoint_syncs_no_rows_and_warns(
+ self, MockSession, endpoint: str, status_code: int, body: dict[str, Any], feature: str
+ ) -> None:
+ session = MockSession.return_value
+ path = PAGERDUTY_ENDPOINTS[endpoint].path
+ _wire(session, [_error_response(status_code, path=path, body=body)])
+ logger = mock.MagicMock()
+
+ rows = _rows(
+ pagerduty_source(
+ "tok", endpoint, team_id=1, job_id="j", resumable_source_manager=_make_manager(), logger=logger
+ )
+ )
+ assert rows == []
+ warning = logger.warning.call_args.args[0]
+ assert f"does not include {feature}" in warning
+ assert f"the {endpoint} table synced no rows" in warning
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_ungated_endpoint_still_fails_on_404(self, MockSession) -> None:
+ # Only endpoints declaring a plan-gated feature swallow a 404; elsewhere it is a real
+ # failure the sync must surface.
+ session = MockSession.return_value
+ _wire(session, [_error_response(404, path="/users")])
+
+ with pytest.raises(HTTPError):
+ _rows(
+ pagerduty_source(
+ "tok",
+ "users",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ logger=mock.MagicMock(),
+ )
+ )
+
+ @pytest.mark.parametrize("status_code", [401, 403])
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_plan_gated_endpoint_still_fails_on_other_statuses(self, MockSession, status_code: int) -> None:
+ # Only 402 and 404 mean "your plan does not include this"; a credential problem on a gated
+ # endpoint must still fail rather than be reported as an empty table.
+ session = MockSession.return_value
+ _wire(session, [_error_response(status_code, path="/teams")])
+ logger = mock.MagicMock()
+
+ with pytest.raises(HTTPError):
+ _rows(
+ pagerduty_source(
+ "tok", "teams", team_id=1, job_id="j", resumable_source_manager=_make_manager(), logger=logger
+ )
+ )
+ logger.warning.assert_not_called()
+
+ @pytest.mark.parametrize(
+ "endpoint,wrong_status",
+ [
+ # teams is plan-gated at 402, not 404; priorities is plan-gated at 404, not 402. The
+ # gated status is endpoint-specific, so the other status on that same endpoint is a
+ # genuine failure and must still raise rather than being read as "plan lacks it".
+ ("teams", 404),
+ ("priorities", 402),
+ ],
+ )
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_plan_gated_endpoint_fails_on_the_other_endpoints_gated_status(
+ self, MockSession, endpoint: str, wrong_status: int
+ ) -> None:
+ session = MockSession.return_value
+ path = PAGERDUTY_ENDPOINTS[endpoint].path
+ _wire(session, [_error_response(wrong_status, path=path)])
+ logger = mock.MagicMock()
+
+ with pytest.raises(HTTPError):
+ _rows(
+ pagerduty_source(
+ "tok", endpoint, team_id=1, job_id="j", resumable_source_manager=_make_manager(), logger=logger
+ )
+ )
+ logger.warning.assert_not_called()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/tests/test_pagerduty_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/tests/test_pagerduty_source.py
index 568201651fa7..a83662c22a27 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/tests/test_pagerduty_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pagerduty/tests/test_pagerduty_source.py
@@ -55,3 +55,30 @@ class TestPagerDutySource:
ok, error = self.source.validate_credentials(self.config, team_id=1, schema_name="incidents")
assert ok is False
assert error == "Your PagerDuty API key does not have access to this resource"
+
+ @pytest.mark.parametrize(
+ "schema_name,status_code,expected_ok",
+ [
+ # A plan-gated table answers 402 (teams) or 404 (priorities) for every account whose
+ # plan lacks the feature. The sync skips those tables, so their settings must stay
+ # reachable instead of returning an error.
+ ("teams", 402, True),
+ ("priorities", 404, True),
+ # The same statuses on a table no plan gates are real failures.
+ ("incidents", 402, False),
+ ("users", 404, False),
+ # Each gated table has one specific gated status; the other status on that same table
+ # is a genuine failure, not "plan lacks it".
+ ("teams", 404, False),
+ ("priorities", 402, False),
+ ],
+ )
+ def test_validate_credentials_accepts_plan_gated_statuses(
+ self, schema_name: str, status_code: int, expected_ok: bool
+ ) -> None:
+ with patch(
+ f"{PAGERDUTY_MODULE}.source.validate_pagerduty_credentials",
+ return_value=(False, status_code, f"PagerDuty API error (status {status_code})"),
+ ):
+ ok, _error = self.source.validate_credentials(self.config, team_id=1, schema_name=schema_name)
+ assert ok is expected_ok