SyntaxWarning: 'return' in a 'finally' block (Python 3.14)
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 70/100
Rechercherichtung
Beginnen Sie in datadog_lambda/wrapper.py bei _LambdaDecorator.call und untersuchen Sie den try/except/finally-Kontrollfluss, insbesondere die bei Zeile 203 gemeldete return-Anweisung. Überprüfen Sie die vier im Issue beschriebenen Ausführungspfade und fügen Sie Tests hinzu bzw. aktualisieren Sie sie, sodass der Import unter Python 3.14 keine SyntaxWarning ausgibt, während blockierende und normale Antworten weiterhin korrekt bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 102
- Forks
- 52
- Ø Merge
- 5 T. 19 Std.
- Gemergte PRs (30 T.)
- 2
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus DataDog/datadog-lambda-python
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
DataDog/datadog-lambda-python#755 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 30/100
DataDog/datadog-lambda-python#688 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
DataDog/datadog-lambda-python#682 · 1 Kommentar ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
DataDog/datadog-lambda-python#666 · 1 Reaktion ·
-
DataDog/datadog-lambda-python#633 · 2 Kommentare · 1 zugewiesene Person ·
Alle Issues in DataDog/datadog-lambda-python
Ähnliche Issues
-
documentation help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
simonw/sqlite-utils#872 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100