-
Notifications
You must be signed in to change notification settings - Fork 450
feat(event-handler): add support for Pydantic Field discriminator in validation #7227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
…validation (aws-powertools#5953) Enable use of Field(discriminator='...') with tagged unions in event handler validation. This allows developers to use Pydantic's native discriminator syntax instead of requiring Powertools-specific Param annotations. - Handle Field(discriminator) + Body() combination in get_field_info_annotated_type - Preserve discriminator metadata when creating TypeAdapter in ModelField - Add comprehensive tests for discriminator validation and Field features
Hey @dap0am please run |
Done, thanks. |
Thanks for fixing! You can run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @dap0am! Please let me know if you need any help here.
|
Summary
This PR adds support for Pydantic's
Field(discriminator='...')
syntax in event handler validation, enabling tagged unions to work correctly with the validation middleware.Fixes #5953
Changes
get_field_info_annotated_type()
inparams.py
to handleField(discriminator) + Body()
combinationsModelField.__post_init__()
incompat.py
to preserve discriminator metadata when creating TypeAdaptersTesting
test_field_discriminator_validation()
to verify discriminator functionality with tagged unionstest_field_other_features_still_work()
to ensure other Field features remain functionalExample Usage
Checklist
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.