SyntaxWarning: 'return' in a 'finally' block (Python 3.14)
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 70/100
Piste de recherche
Commencez dans datadog_lambda/wrapper.py, au niveau de _LambdaDecorator.call, et examinez le flux de contrôle try/except/finally, en particulier le return signalé à la ligne 203. Vérifiez les quatre chemins d’exécution décrits dans l’issue et ajoutez ou mettez à jour les tests afin que l’importation avec Python 3.14 n’émette aucun SyntaxWarning, tout en garantissant que les réponses bloquantes et normales restent correctes.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- Python
- Étoiles
- 102
- Forks
- 52
- Merge moyen
- 5 j 19 h
- PR mergées (30 j)
- 2
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de DataDog/datadog-lambda-python
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
DataDog/datadog-lambda-python#755 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 30/100
DataDog/datadog-lambda-python#688 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
DataDog/datadog-lambda-python#682 · 1 commentaire ·
-
Migrate from ujson to orjson Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
DataDog/datadog-lambda-python#666 · 1 réaction ·
-
DataDog/datadog-lambda-python#633 · 2 commentaires · 1 personne assignée ·
Toutes les issues de DataDog/datadog-lambda-python
Issues similaires
-
documentation help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
simonw/sqlite-utils#872 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100