Skip to content

Bug: JSON serialization should be the last operation before returning a response from an event handler #3391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rubenfonseca opened this issue Nov 22, 2023 · 2 comments · Fixed by #3392
Assignees
Labels
bug Something isn't working event_handlers

Comments

@rubenfonseca
Copy link
Contributor

Expected Behaviour

Middleware writers should access the original return of the handler, before serialization happens.

Current Behaviour

When writing your own middleware, you only get access to a serialized version of the handler response, and not the original. This introduces challenges when you want to manipulate the original response.

Code snippet

class MyMiddleware(BaseMiddlewareHandler):
    def handler(self, app: EventHandlerInstance, next_middleware: NextMiddleware) -> Response:
        # Call the handler by calling the next middleware
        response = next_middleware(app)

        response.body # this should be the original response, not a serialized version

Possible Solution

Move the serialization as the last operation to be done before returning, after running all the middlewares.

Steps to Reproduce

See code snippet above

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.7

Packaging format used

PyPi

Debugging logs

No response

Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Nov 22, 2023
Copy link
Contributor

This is now released under 2.28.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event_handlers
Projects
Status: Shipped
1 participant