Skip to content

Feature request: Enable to change the deserializer body #6600

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

Open
1 of 2 tasks
LucasCMFBraga opened this issue May 2, 2025 · 2 comments
Open
1 of 2 tasks

Feature request: Enable to change the deserializer body #6600

LucasCMFBraga opened this issue May 2, 2025 · 2 comments
Assignees
Labels
feature-request feature request triage Pending triage from maintainers

Comments

@LucasCMFBraga
Copy link

LucasCMFBraga commented May 2, 2025

Use case

I updated the schema of my application, changing the amount field from int to float to comply with my company's requirements. However, I noticed that the default JSON parser was losing floating-point precision during requests.

def test_api_gateway_resolver_numeric_value():
    app = ApiGatewayResolver()

    @app.post("/my/path")
    def test_handler():
        return app.current_event.json_body

    # WHEN calling the event handler
    event = {}
    event.update(LOAD_GW_EVENT)
    event["body"] = '{"amount":  2.2999999999999998}'
    event["httpMethod"] = "POST"

    result = app(event, {})
    # THEN process event correctly
    assert result["statusCode"] == 200
    assert result["multiValueHeaders"]["Content-Type"] == [content_types.APPLICATION_JSON]
    assert result["body"] == '{"amount":  2.2999999999999998}' # assert '{"amount":2.3}' == '{"amount":  2.2999999999999998}'

Solution/User Experience

I've already implemented a solution and will be opening a PR soon.
The fix involves passing a custom deserializer instance to the ApiGatewayResolver constructor to handle floating-point precision correctly.

Alternative solutions

Acknowledgment

Copy link

boring-cyborg bot commented May 2, 2025

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@LucasCMFBraga LucasCMFBraga changed the title Feature request: Enable to change the desarterializer body Feature request: Enable to change the deserializer body May 2, 2025
@leandrodamascena
Copy link
Contributor

Hey @LucasCMFBraga! Thanks for opening this issue and sending the PR. Sorry for the late reply!

I'll take a look in the PR right now!!

@leandrodamascena leandrodamascena moved this from Triage to Working on it in Powertools for AWS Lambda (Python) May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request triage Pending triage from maintainers
Projects
Status: Working on it
Development

No branches or pull requests

2 participants