Skip to content

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

Merged
leandrodamascena merged 2 commits into
aws-powertools:developfrom
TanbirRamim:fix/openapi-generic-alias-response-model
Sep 14, 2026
Merged

leandrodamascena merged 2 commits into
aws-powertools:developfrom
TanbirRamim:fix/openapi-generic-alias-response-model

Conversation

@TanbirRamim

Copy link
Copy Markdown
Contributor

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

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Tanbir, this is a very good fix. I reproduced the StopIteration on develop and confirmed that both list[Model] and dict[str, Model] generate the expected schemas with this change.

Using equality here makes sense because deepcopy creates a new generic alias, while regular model classes keep the same behavior. I’ll approve and merge this.

@mergify

mergify Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.65%. Comparing base (237f4db) to head (0df6ff7).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8453   +/-   ##
========================================
  Coverage    96.65%   96.65%           
========================================
  Files          296      296           
  Lines        14905    14905           
  Branches      1266     1266           
========================================
  Hits         14407    14407           
  Misses         363      363           
  Partials       135      135           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena
leandrodamascena merged commit 362a797 into aws-powertools:develop Sep 14, 2026
15 checks passed
@boring-cyborg

boring-cyborg Bot commented Sep 14, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@powertools-for-aws-oss-automation

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

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]

3 participants