Skip to content

Commit

Permalink
Fix issue with flask url handler returning an iterator.
Browse files Browse the repository at this point in the history
If the iterator does some actual job then yield's part of response, sentry sdk would not catch anything after the url handler itself returned, and will miss everything being done in the iterator. This fixes the issue.

Signed-off-by: Wei Mingzhi <[email protected]>
  • Loading branch information
weimzh committed Nov 10, 2024
1 parent 200d0cd commit ba7ea2b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sentry_sdk/integrations/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,17 @@ def __call__(self, environ, start_response):
_sentry_start_response, start_response, transaction
),
)
if hasattr(response, "__iter__"):
scoped_response = _ScopedResponse(scope, response)
for it in scoped_response:
yield it
except BaseException:
reraise(*_capture_exception())
finally:
_wsgi_middleware_applied.set(False)

return _ScopedResponse(scope, response)
if not hasattr(response, "__iter__"):
return _ScopedResponse(scope, response)


def _sentry_start_response( # type: ignore
Expand Down

0 comments on commit ba7ea2b

Please sign in to comment.