Skip to content

Commit d54442e

Browse files
committed
elasticapm/contrib/django: swallow exceptions explicitly
In 3.14 after https://peps.python.org/pep-0765/ the pattern of using return in a finally block is considered harmful. I guess the intent here is to just swallow any exception raised in the try block and always return the response.
1 parent 14f52fe commit d54442e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

elasticapm/contrib/django/middleware/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ def process_request_wrapper(wrapped, instance, args, kwargs):
110110
elasticapm.set_transaction_name(
111111
build_name_with_http_method_prefix(get_name_from_middleware(wrapped, instance), request)
112112
)
113-
finally:
114-
return response
113+
except Exception:
114+
pass
115+
return response
115116

116117

117118
def process_response_wrapper(wrapped, instance, args, kwargs):
@@ -125,8 +126,9 @@ def process_response_wrapper(wrapped, instance, args, kwargs):
125126
elasticapm.set_transaction_name(
126127
build_name_with_http_method_prefix(get_name_from_middleware(wrapped, instance), request)
127128
)
128-
finally:
129-
return response
129+
except Exception:
130+
pass
131+
return response
130132

131133

132134
class TracingMiddleware(MiddlewareMixin, ElasticAPMClientMiddlewareMixin):

0 commit comments

Comments
 (0)