From a0f11e5a7f184bae1148f68019586520dacf3506 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 4 May 2023 12:17:12 +0200 Subject: [PATCH] fix(crons): Fix KeyError in capture_checkin if SDK is not initialized (#2073) When Sentry SDK was not initialized, any calls to capture_checkin() raised a KeyError. This made all calls to functions decorated with @sentry_sdk.monitor() fail, because capture_checkin() is always called within the decorator. Co-authored-by: Jan Smitka --- tests/test_crons.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_crons.py b/tests/test_crons.py index 26adbb746b..0a940c52ad 100644 --- a/tests/test_crons.py +++ b/tests/test_crons.py @@ -133,3 +133,15 @@ def test_monitor_config(sentry_init, capture_envelopes): assert check_in["monitor_slug"] == "abc123" assert "monitor_config" not in check_in + + +def test_capture_checkin_sdk_not_initialized(): + # Tests that the capture_checkin does not raise an error when Sentry SDK is not initialized. + # sentry_init() is intentionally omitted. + check_in_id = capture_checkin( + monitor_slug="abc123", + check_in_id="112233", + status=None, + duration=None, + ) + assert check_in_id == "112233"