-
Notifications
You must be signed in to change notification settings - Fork 420
Bug: APIGatewayHttpResolver with validation enabled returns HTTP 422 when using single value query parameters #3732
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
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @DariusKunce this is on my list for verification tomorrow, thanks for submitting it! |
@DariusKunce Confirmed! We'll add this into the next sprint to fix def test_weird_issue():
# GIVEN a Http API V2 proxy type event
app = APIGatewayRestResolver(enable_validation=True)
class FunkyTown(BaseModel):
parameter: str
@app.get("/my/path")
def my_path(
parameter: Annotated[str | None, Query(alias="parameter1")] = None,
) -> Response[FunkyTown]:
assert isinstance(app.current_event, APIGatewayProxyEvent)
assert parameter == "value"
return Response(200, content_types.APPLICATION_JSON, FunkyTown(parameter=parameter))
result = app(load_event("apiGatewayProxyEvent.json"), {})
print(result)
assert result["statusCode"] == 200 |
@DariusKunce we're aiming to make a release tomorrow with this fix ahead of schedule -- let us know if you're blocked by this and we can make it today. |
The issue isn't related to the alias but the fact that the With With I was able to find this as I was trying to validate the min length of a query string parameter ( The line truncating the value is here |
Thanks a lot for the timely comment @jpoissant. @rubenfonseca i think we had mixed messaging and this wasn't fixed -- if you can't look into it tomorrow morning before release, let me know pretty plz |
Thank you so much @jpoissant I'm looking at this right now |
@jpoissant I need to understand the problem a little bit better, since I'm unable to reproduce the problem. Can you please confirm which event handler are you using? Is it the APIGatewayRestResolver ? Reason I'm asking is that the REST API Gateway will always send So I need to understand what scenario do you have where you only have |
@rubenfonseca I am using the |
@rubenfonseca would it be better to open a new bug for the |
No that helps, let me investigate today and I'll get back to you today! |
Got it, was able to reproduce the problem! Fix incoming |
Coming up in this week's release! Just merged Ruben's PR |
We're making a release today after we push a non-related and last bugfix for this release 🚀 |
This is now released under 2.34.0 version! |
Expected Behaviour
When using Amazon Api Gateway REST API to invoke an AWS Lambda using proxy integration, calling API with a single query parameter should return HTTP 200 with Lambda Powertools validation enabled.
This is also how it is documented here: https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/#validating-query-strings
Current Behaviour
Calling API with
GET /my-path?productType=Category1
returns HTTP 422:Code snippet
Possible Solution
Can be fixed by changing query param type to list:
Steps to Reproduce
In AWS:
Locally:
The issue is this line of code: https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py#L123
Lambda Powertools should additionally check dictionary values in
multiValueQueryStringParameters
if they contain only one value, and validate accordingly to be of typestr
instead oflist[str]
.Powertools for AWS Lambda (Python) version
2.33.0
AWS Lambda function runtime
3.12
Packaging format used
PyPi
Debugging logs
No response
The text was updated successfully, but these errors were encountered: