Skip to content

Commit 59b55a4

Browse files
committed
fix: sentry client is None
1 parent a2a8aa0 commit 59b55a4

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ repos:
2727
- pyflakes==2.4.0
2828

2929
- repo: https://github.com/pycqa/isort
30-
rev: 5.10.1
30+
rev: 5.12.0
3131
hooks:
3232
- id: isort
3333
args: ["-m=VERTICAL_HANGING_INDENT", "--combine-as", "--profile=black"]

sentry_dynamic_sampling_lib/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def init_wrapper():
4242
sentry_sdk: sentry_sdk_type = importlib.import_module("sentry_sdk")
4343
client = sentry_sdk.Hub.current.client
4444

45+
if client is None:
46+
return
47+
4548
if CONTROLLER_HOST:
4649
app_key = build_app_key(client.options)
4750
controller_endpoint = urljoin(CONTROLLER_HOST, CONTROLLER_PATH)

tests/test_hooks.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from unittest.mock import Mock, patch
1+
from unittest.mock import MagicMock, Mock, patch
22

33
import pytest
44

@@ -26,6 +26,18 @@ def test_init_wrapper_no_sentry(importlib_mock: Mock):
2626
importlib_mock.import_module.assert_not_called()
2727

2828

29+
@patch("sentry_dynamic_sampling_lib.importlib")
30+
def test_init_wrapper_no_client(importlib_mock: Mock):
31+
importlib_mock.util.find_spec.return_value = True
32+
sentry_sdk = MagicMock()
33+
sentry_sdk.Hub.current.client = None
34+
importlib_mock.import_module.return_value = sentry_sdk
35+
36+
init_wrapper()
37+
importlib_mock.util.find_spec.assert_called_once_with("sentry_sdk")
38+
importlib_mock.import_module.assert_called_once_with("sentry_sdk")
39+
40+
2941
@patch("sentry_dynamic_sampling_lib.TraceSampler")
3042
@patch("sentry_dynamic_sampling_lib.importlib")
3143
def test_init_wrapper_no_controller(importlib_mock: Mock, trace_sampler: Mock):

0 commit comments

Comments
 (0)