Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ async def sentry_wrapped_error_handler(request, exception):
finally:
# As mentioned in previous comment in _startup, this can be removed
# after https://github.com/sanic-org/sanic/issues/2297 is resolved
if SanicIntegration.version >= (21, 9):
if SanicIntegration.version == (21, 9):
await _hub_exit(request)

return sentry_wrapped_error_handler
Expand Down
16 changes: 11 additions & 5 deletions tests/integrations/sanic/test_sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import random
import asyncio
from unittest.mock import Mock

import pytest

Expand All @@ -10,7 +11,7 @@

from sanic import Sanic, request, response, __version__ as SANIC_VERSION_RAW
from sanic.response import HTTPResponse
from sanic.exceptions import abort
from sanic.exceptions import SanicException

SANIC_VERSION = tuple(map(int, SANIC_VERSION_RAW.split(".")))

Expand All @@ -20,9 +21,9 @@ def app():
if SANIC_VERSION >= (20, 12):
# Build (20.12.0) adds a feature where the instance is stored in an internal class
# registry for later retrieval, and so add register=False to disable that
app = Sanic(__name__, register=False)
app = Sanic("Test", register=False)
else:
app = Sanic(__name__)
app = Sanic("Test")

@app.route("/message")
def hi(request):
Expand Down Expand Up @@ -90,7 +91,7 @@ def test_bad_request_not_captured(sentry_init, app, capture_events):

@app.route("/")
def index(request):
abort(400)
raise SanicException("...", status_code=400)

request, response = app.test_client.get("/")
assert response.status == 400
Expand Down Expand Up @@ -178,7 +179,12 @@ class MockAsyncStreamer:
def __init__(self, request_body):
self.request_body = request_body
self.iter = iter(self.request_body)
self.response = b"success"

if SANIC_VERSION >= (21, 12):
self.response = None
self.stage = Mock()
else:
self.response = b"success"

def respond(self, response):
responses.append(response)
Expand Down