SyntaxWarning: 'return' in a 'finally' block (Python 3.14)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 70/100
Direzione di ricerca
Inizia in datadog_lambda/wrapper.py, all’interno di _LambdaDecorator.call, e analizza il flusso di controllo try/except/finally, in particolare il return segnalato alla riga 203. Verifica i quattro percorsi di esecuzione descritti nell’issue e aggiungi o aggiorna i test in modo che l’importazione con Python 3.14 non emetta alcun SyntaxWarning, mantenendo corrette le risposte bloccanti e normali.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 102
- Fork
- 52
- Merge medio
- 5g 19h
- PR unite (30g)
- 2
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di DataDog/datadog-lambda-python
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
DataDog/datadog-lambda-python#755 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
DataDog/datadog-lambda-python#688 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
DataDog/datadog-lambda-python#682 · 1 commento ·
-
Migrate from ujson to orjson Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
DataDog/datadog-lambda-python#666 · 1 reazione ·
-
DataDog/datadog-lambda-python#633 · 2 commenti · 1 assegnatario ·
Tutte le issue di DataDog/datadog-lambda-python
Issue simili
-
documentation help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
simonw/sqlite-utils#872 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100