Skip to content

Commit 78e7687

Browse files
committed
Fix issue with flask url handler returning an iterator.
If the iterator acts like doing some actual job then yield part of response, sentry sdk would not catch anything after the url handler itself ended. This fixes the issue. Signed-off-by: Wei Mingzhi <[email protected]>
1 parent 200d0cd commit 78e7687

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sentry_sdk/integrations/wsgi.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,17 @@ def __call__(self, environ, start_response):
134134
_sentry_start_response, start_response, transaction
135135
),
136136
)
137+
if hasattr(response, "__iter__"):
138+
scoped_response = _ScopedResponse(scope, response)
139+
for it in scoped_response:
140+
yield it
137141
except BaseException:
138142
reraise(*_capture_exception())
139143
finally:
140144
_wsgi_middleware_applied.set(False)
141145

142-
return _ScopedResponse(scope, response)
146+
if not hasattr(response, "__iter__"):
147+
return _ScopedResponse(scope, response)
143148

144149

145150
def _sentry_start_response( # type: ignore

0 commit comments

Comments
 (0)