File tree 2 files changed +38
-2
lines changed
tests/integrations/falcon
2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -206,13 +206,20 @@ def _patch_prepare_middleware():
206
206
original_prepare_middleware = falcon_helpers .prepare_middleware
207
207
208
208
def sentry_patched_prepare_middleware (
209
- middleware = None , independent_middleware = False
209
+ middleware = None , independent_middleware = False , asgi = False
210
210
):
211
- # type: (Any, Any) -> Any
211
+ # type: (Any, Any, bool) -> Any
212
+ if asgi :
213
+ # We don't support ASGI Falcon apps, so we don't patch anything here
214
+ return original_prepare_middleware (middleware , independent_middleware , asgi )
215
+
212
216
hub = Hub .current
213
217
integration = hub .get_integration (FalconIntegration )
214
218
if integration is not None :
215
219
middleware = [SentryFalconMiddleware ()] + (middleware or [])
220
+
221
+ # We intentionally omit the asgi argument here, since the default is False anyways,
222
+ # and this way, we remain backwards-compatible with pre-3.0.0 Falcon versions.
216
223
return original_prepare_middleware (middleware , independent_middleware )
217
224
218
225
falcon_helpers .prepare_middleware = sentry_patched_prepare_middleware
Original file line number Diff line number Diff line change 13
13
from sentry_sdk .integrations .logging import LoggingIntegration
14
14
15
15
16
+ try :
17
+ import falcon .asgi
18
+ except ImportError :
19
+ pass
20
+ else :
21
+ import falcon .inspect # We only need this module for the ASGI test
22
+
23
+
16
24
@pytest .fixture
17
25
def make_app (sentry_init ):
18
26
def inner ():
@@ -391,3 +399,24 @@ def generator():
391
399
392
400
with sentry_sdk .configure_scope () as scope :
393
401
assert not scope ._tags ["request_data" ]
402
+
403
+
404
+ @pytest .mark .skipif (
405
+ not hasattr (falcon , "asgi" ), reason = "This Falcon version lacks ASGI support."
406
+ )
407
+ def test_falcon_not_breaking_asgi (sentry_init ):
408
+ """
409
+ This test simply verifies that the Falcon integration does not break ASGI
410
+ Falcon apps.
411
+
412
+ The test does not verify ASGI Falcon support, since our Falcon integration
413
+ currently lacks support for ASGI Falcon apps.
414
+ """
415
+ sentry_init (integrations = [FalconIntegration ()])
416
+
417
+ asgi_app = falcon .asgi .App ()
418
+
419
+ try :
420
+ falcon .inspect .inspect_app (asgi_app )
421
+ except TypeError :
422
+ pytest .fail ("Falcon integration causing errors in ASGI apps." )
You can’t perform that action at this time.
0 commit comments