Repository navigation
fix(parser): accept multi-value headers and query strings in VPC Lattice v2 events - #8774
Manishram-ai wants to merge 1 commit into
Conversation
…ice v2 events VPC Lattice sends every header and query string value in a V2 event as a list, even when there is only one value. VpcLatticeV2Model typed both fields as dict[str, str], so every real V2 event failed validation and VpcLatticeV2Envelope could not parse any of them. Type both fields as dict[str, list[str]], matching the V2 event structure in the VPC Lattice docs and the TypeScript parser. The parser tests now use the list-shaped fixtures, plus the event captured from a live V2 target group.
|
blacksoxx
left a comment
There was a problem hiding this comment.
Reads consistent with the service contract to me; I did not run the tests here. One P2 inline on compatibility, which is a maintainer call.
The list shape matches the VPC Lattice docs for the V2 event structure, the captured fixture, the TypeScript fix and the data class, whose query_string_parameters docstring already describes the dict[str, list[str]] shape and joins it with commas. Both fixtures used here carry lists for headers and query strings, so the swapped references in the existing tests hold.
Validation: read the diff at 902d0bc against base f71c5e3; checked the three fixtures and data_classes/vpc_lattice.py on develop. Not run: pytest, mypy. Related: #8777 reports the same bug, #8776 the resolver side of it.
| ) | ||
| headers: dict[str, str] = Field( | ||
| description="The request headers as key-value pairs.", | ||
| headers: dict[str, list[str]] = Field( |
There was a problem hiding this comment.
[P2] This turns a ValidationError on for events shaped like the old fixture, which the model accepts on develop. AGENTS.md and ADR 0006 ask for a PowertoolsUserWarning now and the hard failure in the next major when an accepted input turns out to be wrong. One way that keeps the list type: a field_validator("headers", "query_string_parameters", mode="before") that wraps a str value into a one-item list and warns. Whether that is wanted for a shape the service never sends is the maintainers' call; you already offer it in the description, so this is only to make the choice visible.
There was a problem hiding this comment.
Thanks for reading through it. I went with the bug fix bullet in ADR 0006, since VPC Lattice never sends plain string values, so the old fixture doesn't match the AWS contract. If the maintainers would rather keep accepting strings with a warning, I'll add the field_validator you described.
|
Thanks for this, and for the clean diagnosis in #8773. I am closing it, and I want to be upfront about why: this bug makes |



Issue number:
closes #8773
Summary
Changes
headersandquery_string_parametersinVpcLatticeV2Modelare nowdict[str, list[str]]. VPC Lattice sends every header and query string value in a V2 event as a list, even a single one (docs). I updated the field descriptions and examples to match.vpcLatticeV2Event.json, which has plain string values that VPC Lattice doesn't send. They now usevpcLatticeV2EventWithHeaders.json, which has the same request context with list values. I didn't change any fixtures, since other tests still usevpcLatticeV2Event.json.vpcLatticeV2EventWithQueryString.json), once with the model and once throughVpcLatticeV2Envelope.This is the same fix as aws-powertools/powertools-lambda-typescript#5773.
User experience
Before, every real V2 event failed with a
ValidationError, soVpcLatticeV2ModelandVpcLatticeV2Envelopecouldn't be used with VPC Lattice. Now they parse, and the values come back as lists, like{"header1": ["value1", "value2"]}.Events with plain string values, like the old test fixture, fail validation now. VPC Lattice never sends that shape, so I treated this as a fix to match the AWS contract (ADR 0006). If you'd rather keep accepting strings with a
PowertoolsUserWarninguntil the next major, I'm happy to change it.Verification
develop, 6 of the 7 tests intests/unit/parser/_pydantic/test_vpc_latticev2.pyfail: the 4 existing tests that now use list values and the 2 new ones. All 7 pass with this change.tests/unit/parser,tests/unit/data_classes/required_dependencies,tests/functional/parserandtests/functional/event_handler: 1701 passed, 1 skipped (Python 3.12).ruff format --check,ruff checkandmypyare clean on the changed files.tests/events.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.