Skip to content

Commit 7d739fa

Browse files
feat(sanic): Sanic v21.12 support (getsentry#1292)
* Set version check for v21.9 only * Upgrade tests for v21.12 compat * Add message to exception in tests Co-authored-by: Neel Shah <neelshah.sa@gmail.com>
1 parent 2246620 commit 7d739fa

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

sentry_sdk/integrations/sanic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ async def sentry_wrapped_error_handler(request, exception):
222222
finally:
223223
# As mentioned in previous comment in _startup, this can be removed
224224
# after https://github.com/sanic-org/sanic/issues/2297 is resolved
225-
if SanicIntegration.version >= (21, 9):
225+
if SanicIntegration.version == (21, 9):
226226
await _hub_exit(request)
227227

228228
return sentry_wrapped_error_handler

tests/integrations/sanic/test_sanic.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import random
44
import asyncio
5+
from unittest.mock import Mock
56

67
import pytest
78

@@ -10,7 +11,7 @@
1011

1112
from sanic import Sanic, request, response, __version__ as SANIC_VERSION_RAW
1213
from sanic.response import HTTPResponse
13-
from sanic.exceptions import abort
14+
from sanic.exceptions import SanicException
1415

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

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

2728
@app.route("/message")
2829
def hi(request):
@@ -90,7 +91,7 @@ def test_bad_request_not_captured(sentry_init, app, capture_events):
9091

9192
@app.route("/")
9293
def index(request):
93-
abort(400)
94+
raise SanicException("...", status_code=400)
9495

9596
request, response = app.test_client.get("/")
9697
assert response.status == 400
@@ -178,7 +179,12 @@ class MockAsyncStreamer:
178179
def __init__(self, request_body):
179180
self.request_body = request_body
180181
self.iter = iter(self.request_body)
181-
self.response = b"success"
182+
183+
if SANIC_VERSION >= (21, 12):
184+
self.response = None
185+
self.stage = Mock()
186+
else:
187+
self.response = b"success"
182188

183189
def respond(self, response):
184190
responses.append(response)

0 commit comments

Comments
 (0)