Skip to content

fix(event_handler): match generic alias response models in OpenAPI schema - #8453

Open
TanbirRamim wants to merge 1 commit into
aws-powertools:developfrom
TanbirRamim:fix/openapi-generic-alias-response-model
Open

fix(event_handler): match generic alias response models in OpenAPI schema#8453
TanbirRamim wants to merge 1 commit into
aws-powertools:developfrom
TanbirRamim:fix/openapi-generic-alias-response-model

Conversation

@TanbirRamim

Copy link
Copy Markdown

Issue number: closes #8450

Summary

Changes

Since custom responses started being deep-copied before their model is resolved, a generic alias such as list[Model] comes back as a new GenericAlias object, so the identity check in _resolve_response_payload never found the matching field and get_openapi_schema() raised StopIteration. This compares the model with == instead of is; plain classes still compare by identity, and generic aliases compare structurally. I added a regression test in test_openapi_responses.py covering list[Model] and dict[str, Model], which fails with StopIteration before the change and passes after; the event_handler functional tests, ruff and mypy all pass locally.

User experience

Before, any route with a generic alias as a custom response model broke OpenAPI schema generation, Swagger and validation setup with StopIteration. After, those routes produce the expected array or object schema again, as they did up to 3.24.0.


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.

…hema

Custom responses are deep-copied before resolving their model, and
deepcopy returns a new object for generic aliases such as list[Model].
The identity check against response_extra_models never matched, so
schema generation raised StopIteration. Compare by equality instead.

Fixes aws-powertools#8450
@TanbirRamim
TanbirRamim requested a review from a team as a code owner September 13, 2026 00:30
@TanbirRamim
TanbirRamim requested review from hjgraca and a lite review from Copilot September 13, 2026 00:30
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@boring-cyborg

boring-cyborg Bot commented Sep 13, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@sonarqubecloud

Copy link
Copy Markdown

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

Labels

event_handlers size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: OpenAPI schema generation raises StopIteration when a custom response model is a generic alias such as list[Model]

2 participants