Repository navigation
fix(event_handler): clear AppSyncEventsResolver context on exception - #8959
Open
mayankcodes-dev wants to merge 1 commit into
Open
mayankcodes-dev wants to merge 1 commit into
mayankcodes-dev wants to merge 1 commit into
Conversation
mayankcodes-dev
requested review from
svozza
and
a balanced review from Copilot
December 5, 2026 04:58
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
This branch has not been deployed
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 #8958
Summary
Changes
Wrap
_setup_context()and event resolution insidetry ... finally: self.clear_context()inAppSyncEventsResolver.resolve()(aws_lambda_powertools/event_handler/events_appsync/appsync_events.py), matchingApiGatewayResolver.resolve(),AppSyncResolver.resolve(), andBedrockAgentFunctionResolver.resolve()(#8874).Added three functional tests in
tests/functional/event_handler/required_dependencies/appsync/test_appsync_events_unauthorized.py:test_publish_clears_context_when_unauthorized_raisedtest_subscribe_clears_context_when_unauthorized_raisedtest_resolve_clears_context_when_event_setup_raisesUser experience
AppSyncEventsResolver.resolve()raisedUnauthorizedException(or failed during event setup),self.clear_context()was skipped, leakingapp.contextentries into subsequent warm Lambda invocations.self.clear_context()always executes in thefinallyblock soapp.contextis cleared even when an exception escapesresolve().Verification
Verified locally against
origin/develop(0bbc252, Python 3.14.4) after the final edit:AssertionError: assert {'user_id': '12345'} == {}) and pass with the fix applied.pytest tests/functional/event_handler/required_dependencies/appsync/ tests/unit/event_handler/_required_dependencies/appsync_events/ -v:104 passed, 1 skipped(1 pre-existing skip intest_appsync_events_resolvers.py:1502).ruff checkandruff format --checkon both modified files: all checks passed,2 files already formatted.mypyon both modified files:Success: no issues found in 2 source files.Prepared with AI assistance and verified locally by @mayankcodes-dev.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.