SyntaxWarning: 'return' in a 'finally' block (Python 3.14)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 70/100
Hướng nghiên cứu
Bắt đầu tại datadog_lambda/wrapper.py, ở _LambdaDecorator.call, và kiểm tra luồng điều khiển try/except/finally, đặc biệt là return được báo cáo ở dòng 203. Xác minh bốn đường dẫn thực thi được mô tả trong issue và thêm hoặc cập nhật các bài kiểm thử để việc import trên Python 3.14 không phát ra SyntaxWarning, đồng thời các response dạng blocking và thông thường vẫn chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Expected Behavior
No warnings emitted during Lambda cold start when importing datadog_lambda.
Actual Behavior
A SyntaxWarning is emitted at module import time (cold start) on Python 3.14:
/var/task/datadog_lambda/wrapper.py:203: SyntaxWarning: 'return' in a 'finally' block
return self.blocking_response
This warning fires every cold start and pollutes CloudWatch logs. Python 3.14 introduced SyntaxWarning for return/break/continue inside finally blocks because such a return silently suppresses any exception that was actively propagating through the try/except.
Steps to Reproduce the Problem
- Deploy a Lambda function using
datadog-lambdaon the Python 3.14 runtime - Trigger a cold start (first invocation or new sandbox)
- Observe the
SyntaxWarningin CloudWatch logs duringINIT_START
Specifications
- Datadog Lambda Library version: 8.123.0
- Python version: 3.14
Root Cause
In _LambdaDecorator.__call__, the finally block contains a return:
finally:
self._after(event, context)
if self.blocking_response:
return self.blocking_response # ← triggers SyntaxWarning in Python 3.14
Proposed Fix
Remove return self.response from the try block and return self.blocking_response from the finally block, deferring both to after the entire try/except/finally:
try:
if self.blocking_response:
return self.blocking_response
self.response = self.func(event, context, **kwargs)
except BlockingException:
self.blocking_response = get_asm_blocked_response(self.event_source)
except Exception:
...
raise
finally:
self._after(event, context)
if self.blocking_response:
return self.blocking_response
return self.response
All four execution paths (block before, block during, block after, normal) remain correct. Happy to open a PR with this fix and updated tests.
Stacktrace
/var/task/datadog_lambda/wrapper.py:203: SyntaxWarning: 'return' in a 'finally' block
return self.blocking_response
- Ngôn ngữ chính
- Python
- Star
- 102
- Fork
- 52
- Merge trung bình
- 5 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 2
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DataDog/datadog-lambda-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
DataDog/datadog-lambda-python#755 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
DataDog/datadog-lambda-python#688 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
DataDog/datadog-lambda-python#682 · 1 bình luận ·
-
Migrate from ujson to orjson Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
DataDog/datadog-lambda-python#666 · 1 reaction ·
-
DataDog/datadog-lambda-python#633 · 2 bình luận · 1 người được giao ·
Tất cả issue của DataDog/datadog-lambda-python
Issue tương tự
-
documentation help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
simonw/sqlite-utils#872 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100