Skip to content

Bug: VPCLatticeV2Resolver with enable_validation fails on every request body (AttributeError: 'list' object has no attribute 'strip') #8776

Open

Description

@AtulJoshi1206

Expected Behaviour

With enable_validation=True, a VPCLatticeV2Resolver route that takes a body parameter (Body(), Form() or a Pydantic model) should parse and validate the request body, the same as the other resolvers do.

Current Behaviour

VPC Lattice V2 sends every header value as a list, for example "content-type": ["application/json"]. OpenAPIRequestValidationMiddleware reads Content-Type as a string in two places:

  • _get_body calls app.current_event.headers.get("content-type", "").strip()
  • handler passes the same value to _is_form_content_type, which also calls .strip()

On a real V2 event both get a list, so every request to a route with a body parameter fails with AttributeError: 'list' object has no attribute 'strip' before it reaches the handler.

Header, query and cookie parameters, CORS and compression already handle list values. Only these two Content-Type reads don't.

Code snippet

from typing import Annotated

from pydantic import BaseModel

from aws_lambda_powertools.event_handler import VPCLatticeV2Resolver
from aws_lambda_powertools.event_handler.openapi.params import Body
from tests.functional.utils import load_event

# Event captured from a live VPC Lattice V2 target group
event = load_event("vpcLatticeV2EventWithQueryString.json")
print("content-type as VPC Lattice V2 sends it:", event["headers"]["content-type"])


class Item(BaseModel):
    hello: str


app = VPCLatticeV2Resolver(enable_validation=True)


@app.post("/echo")
def echo(item: Annotated[Item, Body()]):
    return item.model_dump()


print(app.resolve(event, {}))
# AttributeError: 'list' object has no attribute 'strip'
#   openapi_validation.py:144  content_type = app.current_event.headers.get("content-type", "").strip()

Possible Solution

Read Content-Type through a small helper that joins a list value into a string, and use it in both places. The other resolvers always pass a string there, so nothing changes for them. I have a fix with tests ready and can open a PR once this is triaged.

Steps to Reproduce

  1. Check out develop and run the snippet above from the repo root.
  2. The fixture tests/events/vpcLatticeV2EventWithQueryString.json is the event captured from a live V2 target group in Bug: VpcLatticeV2Schema rejects every real V2 event powertools-lambda-typescript#5764.
  3. A Form() body fails the same way, at the _is_form_content_type call.

Did you run the reproduction yourself?

Yes, I ran it and saw the failure

Powertools for AWS Lambda (Python) version

3.38.0

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Debugging logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions