POST with Form parameter that is a list #7337
-
Hi, I'm trying to parse a POST based Form that has a multi-valued string property. Minimal (untested) example: from typing import Annotated
from aws_lambda_powertools.event_handler import APIGatewayHttpResolver
from aws_lambda_powertools.event_handler.openapi.params import Form
from aws_lambda_powertools.utilities.typing import LambdaContext
app = APIGatewayHttpResolver(
enable_validation=True,
)
@app.post("/example")
def example(
param: Annotated[
str,
Form(),
],
param_list: Annotated[
list[str],
Form(),
] = []
):
pass
def lambda_handler(event: dict, context: LambdaContext) -> dict:
return app.resolve(event, context) I'm testing it by generating a dummy event to the lambda with body content like this: import urlparse.parse
def test_example():
# Also tested with tuple form [("param_list", ["value1", "value2"])]
body = urlparse.parse.urlencode({
"param": "value",
"param_list": ["value1", "value2"]
}, doSeq=True)
event = {
"headers": [
"accept": "application/json",
"content-type": "application/x-www-form-urlencoded"
],
...
"body": body
}
... rest of test elided But I always get response code of 422 like this: {
"statusCode": 422,
"detail": [
{
"loc": [
"body","param_list"
],
"type": "list_type"
}
]
} Any help / advice appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @bdellegrazie I think this is a bug indeed when supporting Form() fields with list. Can you please open an issue with this and then I can fix it? |
Beta Was this translation helpful? Give feedback.
Thanks @bdellegrazie! I'm closing this.