You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: Support types annotated with Field for event_handler validation #5953
My Pydantic models are shared between multiple applications. For example, a client application builds an instance of a model and submits it to the API, which validates the request against the same model.
A few types I want to accept as API payloads or parameters are annotated with Field, mainly tagged unions.
I am aware of the Powertools OpenAPI Param annotations, but they have downsides:
having to import Powertools into non-Lambda projects;
being stuck with a single Param type (i.e. Body, Path, etc) per annotated type, or having to duplicate the arguments for different types
With Powertools 3.5.0, the example code below fails:
with def create_action(action: Action): AssertionError: Param: action can only be a request body, use Body()
with def create_action(action: Annotated[Action, Body()]): AssertionError: Only one FieldInfo can be used per parameter
It would be nice if event_handler would allow nested Field annotations, so that I can apply Annotated[some_type, Body()] to an existing annotated type such as a tagged union.
Are you interested in submitting a PR to implement this support?
I'd like to, but it's not a priority for my employer (the workaround of using a TypeAdapter manually is sufficient) and it will be at least a few weeks before I can look at it on my own time. It's not an urgent request, just an idea for future improvement.
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
Activity
leandrodamascena commentedon Jan 31, 2025
Hi @rtandy! Thanks for opening this issue! Yes, I agree that we need to support this.
Are you interested in submitting a PR to implement this support?
rtandy commentedon Feb 3, 2025
I'd like to, but it's not a priority for my employer (the workaround of using a TypeAdapter manually is sufficient) and it will be at least a few weeks before I can look at it on my own time. It's not an urgent request, just an idea for future improvement.
dap0am commentedon Aug 20, 2025
Can I start working on this? I think I have an idea.
leandrodamascena commentedon Aug 20, 2025
Yes @dap0am please go ahead!
feat(event-handler): add support for Pydantic Field discriminator in …
feat(event-handler): add support for Pydantic Field discriminator in …
powertools-for-aws-oss-automation commentedon Sep 11, 2025
Warning
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.