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

Merged
merged 7 commits into from
Dec 23, 2024

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
@github-actions github-actions bot added bug Something isn't working and removed documentation Improvements or additions to documentation labels Nov 19, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Dec 20, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Dec 20, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Dec 20, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Dec 20, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Dec 20, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Dec 20, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Dec 23, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Dec 23, 2024
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.17%. Comparing base (9a961ec) to head (69adad9).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
...s/utilities/idempotency/serialization/functions.py 88.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5590      +/-   ##
===========================================
- Coverage    96.18%   96.17%   -0.02%     
===========================================
  Files          231      232       +1     
  Lines        10919    10940      +21     
  Branches      2019     2023       +4     
===========================================
+ Hits         10502    10521      +19     
- Misses         328      329       +1     
- Partials        89       90       +1     

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

@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Dec 23, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Dec 23, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Dec 23, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Dec 23, 2024
@leandrodamascena leandrodamascena merged commit 7a7f10c into develop Dec 23, 2024
20 of 22 checks passed
@leandrodamascena leandrodamascena deleted the idempotency-none-type branch December 23, 2024 14:00
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
2 participants