Skip to content

Commit 4fe16a2

Browse files
cursoragentclaude
andcommitted
Preserve existing batcher re-entry guard in flush
Co-Authored-By: gpt-5.3-codex-high <noreply@anthropic.com>
1 parent ac5c6d1 commit 4fe16a2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

sentry_sdk/_batcher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ def kill(self) -> None:
115115
self._flusher = None
116116

117117
def flush(self) -> None:
118+
old_flag = getattr(self._active, "flag", False)
118119
self._active.flag = True
119120
try:
120121
self._flush()
121122
finally:
122-
self._active.flag = False
123+
self._active.flag = old_flag
123124

124125
def _add_to_envelope(self, envelope: "Envelope") -> None:
125126
envelope.add_item(

tests/test_batcher.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from sentry_sdk._batcher import Batcher
2+
3+
4+
class DummyBatcher(Batcher[int]):
5+
def __init__(self) -> None:
6+
super().__init__(
7+
capture_func=lambda envelope: None,
8+
record_lost_func=lambda *args, **kwargs: None,
9+
)
10+
self.flush_calls = 0
11+
12+
def _flush(self):
13+
self.flush_calls += 1
14+
return None
15+
16+
@staticmethod
17+
def _to_transport_format(item):
18+
return item
19+
20+
21+
def test_flush_restores_existing_reentry_guard():
22+
batcher = DummyBatcher()
23+
batcher._active.flag = True
24+
25+
batcher.flush()
26+
27+
assert batcher._active.flag is True
28+
assert batcher.flush_calls == 1

0 commit comments

Comments
 (0)