Skip to content

Bug: Form() field does not handle list parameters #7342

Description

@bdellegrazie

I'm trying to parse a POST based Form that has a multi-valued string property.
However this doesn't appear to work?. It does work for the string parameter, but not for the list.

Minimal 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)

Tested 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"
    }
  ]
}

Thanks!

Originally posted by @bdellegrazie in #7337

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions