Skip to content
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

fix(idempotency): add support for Optional type when serializing output #5590

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #5589

Summary

Changes

This Pull Request addresses an issue with the PydanticSerializer when used in conjunction with the idempotent_function decorator. Currently, the serializer does not support optional return types (Optional[T] or T | None), leading to errors when functions are designed to return None.

Example

@idempotent_function(
    data_keyword_argument="order",
    config=config,
    persistence_store=dynamodb,
    output_serializer=PydanticSerializer(model=OrderOutput),
)
def process_order(order: Order) -> OrderOutput | None:
    if order:
        return OrderOutput(order_id=order.order_id)
    return None

Changes made to fix

  • Type Handling: Modify the type-checking logic in the PydanticSerializer to recognize and accept optional return types.
  • Error Messaging: Implement clear error messages that guide users on supported return types if an invalid type is encountered.
  • Documentation: Updates the documentation to include information about optional return types.

User experience

Customers can now use None as return type.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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.

@leandrodamascena leandrodamascena requested a review from a team as a code owner November 19, 2024 17:45
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation tests labels Nov 19, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 19, 2024
Copy link

sonarcloud bot commented Nov 19, 2024

@github-actions github-actions bot added bug Something isn't working and removed documentation Improvements or additions to documentation labels Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: PydanticSerializer for idempotency utility does not support Optional return types
1 participant