Skip to content

Commit 37ab650

Browse files
untitakersentry-bot
andauthored
fix: Handle exc_info=0 (#905)
Co-authored-by: sentry-bot <[email protected]>
1 parent e6bd271 commit 37ab650

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

sentry_sdk/integrations/logging.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ def _emit(self, record):
183183
client_options = hub.client.options
184184

185185
# exc_info might be None or (None, None, None)
186-
if record.exc_info is not None and record.exc_info[0] is not None:
186+
#
187+
# exc_info may also be any falsy value due to Python stdlib being
188+
# liberal with what it receives and Celery's billiard being "liberal"
189+
# with what it sends. See
190+
# https://github.com/getsentry/sentry-python/issues/904
191+
if record.exc_info and record.exc_info[0] is not None:
187192
event, hint = event_from_exception(
188193
record.exc_info,
189194
client_options=client_options,

tests/integrations/logging/test_logging.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ def test_logging_works_with_many_loggers(sentry_init, capture_events, logger):
3030

3131

3232
@pytest.mark.parametrize("integrations", [None, [], [LoggingIntegration()]])
33-
def test_logging_defaults(integrations, sentry_init, capture_events):
33+
@pytest.mark.parametrize(
34+
"kwargs", [{"exc_info": None}, {}, {"exc_info": 0}, {"exc_info": False}]
35+
)
36+
def test_logging_defaults(integrations, sentry_init, capture_events, kwargs):
3437
sentry_init(integrations=integrations)
3538
events = capture_events()
3639

3740
logger.info("bread")
38-
logger.critical("LOL")
41+
logger.critical("LOL", **kwargs)
3942
(event,) = events
4043

4144
assert event["level"] == "fatal"

0 commit comments

Comments
 (0)