Repository navigation
fix(event_handler): resolve Depends() and Request params with a None default on Python 3.10 - #8649
Merged
Merged
Conversation
…default on Python 3.10 On Python 3.10, typing.get_type_hints wraps the annotation of a parameter whose default is None in Optional[...], hiding the Annotated metadata. Depends() was silently skipped and the parameter received None; a Request parameter with a None default was not injected either. Python 3.11+ stopped wrapping, so only 3.10 was affected. Unwrap Optional/Union before inspecting the annotation.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8649 +/- ##
========================================
Coverage 96.93% 96.93%
========================================
Files 318 318
Lines 16036 16045 +9
Branches 1423 1425 +2
========================================
+ Hits 15545 15554 +9
Misses 349 349
Partials 142 142 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Issue number: closes #8648
Summary
Changes
On Python 3.10,
typing.get_type_hintswraps the annotation of a parameter whose default isNoneinOptional[...]. That hid theAnnotatedmetadata, soDepends()was silently skipped and the parameter receivedNone, and arequest: Request = Noneparameter was not injected either. Python 3.11+ stopped wrapping, so only 3.10 was affected._unwrap_optionalhelper independs.pyreturns the single non-Nonemember of aUnion/Optional, otherwise the annotation itself._get_depends_from_annotation, in theRequestinjection insidesolve_dependencies, and in_find_request_param_name.Depends()with aNonedefault, explicitOptional[Annotated[...]]andAnnotated[...] | None, andrequest: Request = None. All three fail on 3.10 without the change and pass with it.tests/functional/event_handlerandtests/unit/event_handlerpass on 3.10 and 3.14.User experience
Before, on Python 3.10:
After:
{"region": "eu-west-1"}, the same as on 3.11+. No change for 3.11+ and no public API change.Found while running the pre-release smoke test of develop in real Lambda functions on python3.10.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.