Skip to content

Commit 22227f5

Browse files
authored
ref: Use Hub.scope and Hub.client when appropriate (getsentry#744)
1 parent 8c35da5 commit 22227f5

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

sentry_sdk/hub.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def get_integration(
276276
else:
277277
raise ValueError("Integration has no name")
278278

279-
client = self._stack[-1][0]
279+
client = self.client
280280
if client is not None:
281281
rv = client.integrations.get(integration_name)
282282
if rv is not None:
@@ -587,7 +587,7 @@ def end_session(self):
587587
session.close()
588588
if client is not None:
589589
client.capture_session(session)
590-
self._stack[-1][1]._session = None
590+
self.scope._session = None
591591

592592
def stop_auto_session_tracking(self):
593593
# type: (...) -> None

tests/test_basics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ def test_push_scope_callback(sentry_init, null_client, capture_events):
172172
if null_client:
173173
Hub.current.bind_client(None)
174174

175-
outer_scope = Hub.current._stack[-1][1]
175+
outer_scope = Hub.current.scope
176176

177177
calls = []
178178

179179
@push_scope
180180
def _(scope):
181-
assert scope is Hub.current._stack[-1][1]
181+
assert scope is Hub.current.scope
182182
assert scope is not outer_scope
183183
calls.append(1)
184184

@@ -188,7 +188,7 @@ def _(scope):
188188
assert calls == [1]
189189

190190
# Assert scope gets popped correctly
191-
assert Hub.current._stack[-1][1] is outer_scope
191+
assert Hub.current.scope is outer_scope
192192

193193

194194
def test_breadcrumbs(sentry_init, capture_events):

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def test_configure_scope_available(sentry_init, request, monkeypatch):
316316
sentry_init()
317317

318318
with configure_scope() as scope:
319-
assert scope is Hub.current._stack[-1][1]
319+
assert scope is Hub.current.scope
320320
scope.set_tag("foo", "bar")
321321

322322
calls = []
@@ -327,7 +327,7 @@ def callback(scope):
327327

328328
assert configure_scope(callback) is None
329329
assert len(calls) == 1
330-
assert calls[0] is Hub.current._stack[-1][1]
330+
assert calls[0] is Hub.current.scope
331331

332332

333333
@pytest.mark.tests_internal_exceptions

0 commit comments

Comments
 (0)