Skip to content

fix(event_handler): revert regression when validating response #6234

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

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

leandrodamascena
Copy link
Contributor

@leandrodamascena leandrodamascena commented Mar 7, 2025

Issue number: #6216

Summary

Changes

This PR addresses a regression that was introduced by PR #6119. The regression impacts the validation of responses specifically when utilizing the Response object with specific data type.

User experience

The code bellow will fail with this regression

from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response
import json
from pydantic import BaseModel
from typing import List

app = APIGatewayRestResolver(enable_validation=True)

class StatusGroup(BaseModel):
    count: int
    status: str   

def lambda_handler(event, context):
    return app.resolve(event,context)

@app.get("/status", 
        summary="status",
        description="count",
        response_description="status count",
        responses={
            200: {"description": "status count"}
        }
    )
def status( requests:List[str]) -> List[StatusGroup]:
    response = [{"status":"initial","count":1},{"status":"done","count":1}]
    return Response(200, body=json.dumps(response))

def main():
    event = {
        "path": "/status",
        "httpMethod": "GET",
        "requestContext": {"requestId": "227b78aa-779d-47d4-a48e-ce62120393b8"}, 
        "body": '["1","2","3"]'
    }
    response = lambda_handler(event,None)
    print(json.dumps(response,sort_keys=True, indent=4, default=str))

if __name__ == "__main__":
    main()

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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.

@leandrodamascena leandrodamascena requested a review from a team as a code owner March 7, 2025 09:03
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 7, 2025
@github-actions github-actions bot added the bug Something isn't working label Mar 7, 2025
Copy link

sonarqubecloud bot commented Mar 7, 2025

Copy link

codecov bot commented Mar 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.30%. Comparing base (76b4d8f) to head (83b8e01).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6234      +/-   ##
===========================================
+ Coverage    96.28%   96.30%   +0.01%     
===========================================
  Files          240      240              
  Lines        11572    11572              
  Branches       858      858              
===========================================
+ Hits         11142    11144       +2     
+ Misses         337      336       -1     
+ Partials        93       92       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena leandrodamascena requested review from dreamorosi and removed request for anafalcao March 7, 2025 09:11
@leandrodamascena leandrodamascena merged commit 9775975 into develop Mar 7, 2025
21 checks passed
@leandrodamascena leandrodamascena deleted the revert/pr6119 branch March 7, 2025 09:14
@leandrodamascena leandrodamascena self-assigned this Mar 7, 2025
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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Upgrade to 3.7.0 breaks List response validation in APIGatewayRestResolver
2 participants