Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crons): Fix KeyError in capture_checkin if SDK is not initialized #1982

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(crons): Fix KeyError in capture_checkin if SDK is not initialized
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.
jsmitka committed Mar 30, 2023

Verified

This commit was signed with the committer’s verified signature.
commit 6ffa745fa7e1196bbb82e52814e5effc405158d6
4 changes: 2 additions & 2 deletions sentry_sdk/crons.py
Original file line number Diff line number Diff line change
@@ -38,8 +38,8 @@ def _create_checkin_event(
"check_in_id": check_in_id,
"status": status,
"duration": duration,
"environment": options["environment"],
"release": options["release"],
"environment": options.get("environment"),
"release": options.get("release"),
}

return checkin
12 changes: 12 additions & 0 deletions tests/test_crons.py
Original file line number Diff line number Diff line change
@@ -86,3 +86,15 @@ def test_capture_checkin_new_id(sentry_init):
)

assert check_in_id == "a8098c1af86e11dabd1a00112444be1e"


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"