fix(event_handler): preserve comma-separated values in scalar parameters and model fields - #8514
Open
DYNOSuprovo wants to merge 1 commit into
Open
DYNOSuprovo wants to merge 1 commit into
DYNOSuprovo wants to merge 1 commit into
Conversation
…ers and model fields (aws-powertools#8508) Signed-off-by: DYNOSuprovo <[email protected]>
|
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 #8508
Summary
Changes
In the OpenAPI validation middleware:
_process_scalar_paramto check if a parameter's value was split into a list of strings (by proxies such as API Gateway HTTP API v2 or Lambda Function URLs representing multi-value query or header parameters) and rejoin them with",".join(value)when expecting a scalar string. Previously,_process_scalar_paramonly unwrapped single-element lists (len(value) == 1), leaving multi-item lists intact and causing Pydantic to reject valid comma-containing queries or headers with a 422string_typevalidation error._normalize_field_valuefor Pydantic model fields to rejoin string lists with",".join(value)when the target field annotation is not a sequence, instead of returningvalue[0]which caused strings containing commas to be silently truncated.tests/functional/event_handler/_pydantic/test_openapi_validation_middleware.pyverifying comma preservation for scalar query parameters, headers (e.g.X-Forwarded-For), and Pydantic models.User experience
Before:
GET /search?search=hello,worldwheresearch: Annotated[str, Query()]) was rejected with HTTP 422:{"statusCode": 422, "body": "[{\"type\":\"string_type\",\"loc\":[\"query\",\"search\"],\"msg\":\"Input should be a valid string\",\"input\":[\"hello\",\"world\"]}]"}X-Forwarded-For: 203.0.113.9, 10.0.0.1wherex_forwarded_for: Annotated[str, Header()]) was rejected with HTTP 422string_type.search: str) was truncated to only the first segment before the comma ("hello"instead of"hello,world").After:
All query parameters and headers containing commas are properly validated and preserved as full strings (
"hello,world","203.0.113.9, 10.0.0.1") across scalar parameters and Pydantic models, while sequence fields continue to be parsed as list items.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.