: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(oauth): don't capture expected CIMD validation errors as issues (#66110)
posthog[bot]f67b046a9b68
diff --git a/posthog/api/oauth/cimd.py b/posthog/api/oauth/cimd.pyindex ffafdd422b46..75fc4c1c283d 100644--- a/posthog/api/oauth/cimd.py+++ b/posthog/api/oauth/cimd.py@@ -610,7 +610,10 @@ def refresh_cimd_metadata_task(url: str) -> None:try:with ph_scoped_capture() as capture_ph_event:fetch_and_upsert_cimd_application(url, capture_ph_event=capture_ph_event)- except (CIMDFetchError, CIMDValidationError) as e:+ except CIMDValidationError as e:+ # Expected rejection of a non-compliant partner document — log for observability, don't surface as an error.+ logger.warning("cimd_background_refresh_failed", url=url, error=str(e))+ except CIMDFetchError as e:logger.warning("cimd_background_refresh_failed", url=url, error=str(e))capture_exception(e)@@ -637,7 +640,10 @@ def register_cimd_provisioning_application_task(url: str) -> None:"organization_id": str(app.organization_id) if app.organization_id else None,},)- except (CIMDFetchError, CIMDValidationError) as e:+ except CIMDValidationError as e:+ # Expected rejection of a non-compliant partner document — log for observability, don't surface as an error.+ logger.warning("cimd_background_registration_failed", url=url, error=str(e))+ except CIMDFetchError as e:logger.warning("cimd_background_registration_failed", url=url, error=str(e))capture_exception(e)diff --git a/posthog/api/oauth/test_cimd.py b/posthog/api/oauth/test_cimd.pyindex 43d00f753ab5..ab5383c0db91 100644--- a/posthog/api/oauth/test_cimd.py+++ b/posthog/api/oauth/test_cimd.py@@ -30,6 +30,7 @@ from posthog.api.oauth.cimd import (get_or_create_cimd_provisioning_application,is_cimd_client_id,refresh_cimd_metadata_task,+ register_cimd_provisioning_application_task,validate_cimd_url,)from posthog.models.oauth import OAuthApplication, create_cimd_verification_token@@ -373,6 +374,36 @@ class TestGetOrCreateCimdApplication(APIBaseTest):app = OAuthApplication.objects.get(cimd_metadata_url=VALID_CIMD_URL)self.assertEqual(app.name, "Original Name")+ @parameterized.expand(+ [+ ("refresh", refresh_cimd_metadata_task),+ ("registration", register_cimd_provisioning_application_task),+ ]+ )+ @patch("posthog.api.oauth.cimd.capture_exception")+ @patch("posthog.api.oauth.cimd.fetch_and_upsert_cimd_application")+ def test_background_task_does_not_capture_expected_validation_error(+ self, _name, task_fn, mock_fetch, mock_capture, _url_mock+ ):+ # Rejecting a non-compliant partner document is expected, so it must not surface as an error-tracking issue.+ mock_fetch.side_effect = CIMDValidationError("document exceeds the 5120 byte limit")+ task_fn(VALID_CIMD_URL)+ mock_capture.assert_not_called()++ @parameterized.expand(+ [+ ("refresh", refresh_cimd_metadata_task),+ ("registration", register_cimd_provisioning_application_task),+ ]+ )+ @patch("posthog.api.oauth.cimd.capture_exception")+ @patch("posthog.api.oauth.cimd.fetch_and_upsert_cimd_application")+ def test_background_task_captures_unexpected_fetch_error(self, _name, task_fn, mock_fetch, mock_capture, _url_mock):+ error = CIMDFetchError("connection reset")+ mock_fetch.side_effect = error+ task_fn(VALID_CIMD_URL)+ mock_capture.assert_called_once_with(error)+class TestGetApplicationByClientId(APIBaseTest):def setUp(self):