From 2440d4caed796a13ab154648752f93036495651e Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 12 Apr 2026 18:05:46 -0400 Subject: [PATCH] Narrow WSGI fallback to only catch call signature TypeErrors The bare except TypeError when calling mounted apps would silently swallow any TypeError raised inside an ASGI app and incorrectly convert it to WSGI mode. Now only falls back when the error is about call arguments. Co-Authored-By: Claude Opus 4.6 (1M context) --- responder/routes.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/responder/routes.py b/responder/routes.py index 502b4e5..a2a68d2 100644 --- a/responder/routes.py +++ b/responder/routes.py @@ -459,13 +459,22 @@ class Router: if path.startswith(path_prefix): scope["path"] = path[len(path_prefix) :] or "/" scope["root_path"] = root_path + path_prefix - try: - await app(scope, receive, send) - return - except TypeError: - from a2wsgi import WSGIMiddleware - app = WSGIMiddleware(app) + if not (inspect.iscoroutinefunction(app) or hasattr(app, "__asgi_app__")): + # Check if it looks like a WSGI app (callable with fewer params) + try: + await app(scope, receive, send) + return + except TypeError as exc: + # Only fall back to WSGI if the error is about call signature + if "argument" not in str(exc) and "positional" not in str(exc): + raise + from a2wsgi import WSGIMiddleware + + app = WSGIMiddleware(app) + await app(scope, receive, send) + return + else: await app(scope, receive, send) return