Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Enabled support for a custom deserializer to parse the request body #6601

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
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

LucasCMFBraga
Copy link

Issue number: #6600

Summary

This feature allows to pass a custom deserializer to ensure accurate handling of floating-point precision.

Changes

Added support for passing a custom deserializer instance to ApiGatewayResolver to handle JSON numeric values as Decimal, ensuring correct floating-point precision.

`
from tests.functional.utils import load_even
import json
from decimal import Decimal

app = ApiGatewayResolver(deserializer=partial(json.loads, parse_float=Decimal))
`

User experience

Please share what the user experience looks like before and after this change

`
app = ApiGatewayResolver(deserializer=partial(json.loads, parse_float=Decimal))

@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"}'

`

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.

@LucasCMFBraga LucasCMFBraga requested a review from a team as a code owner May 2, 2025 17:56
@LucasCMFBraga LucasCMFBraga requested a review from anafalcao May 2, 2025 17:56
Copy link

boring-cyborg bot commented May 2, 2025

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 2, 2025
Copy link

sonarqubecloud bot commented May 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

1 participant