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): idempotent_function should support standalone falsy values #1669

Conversation

heitorlessa
Copy link
Contributor

Issue number: #1663

Summary

When using idempotent_function for any synchronous Python function (different from Lambda Handler), customers set which keyword argument we should use to hash data as an idempotency key.

We raise RuntimeError for cases where the keyword argument wasn't used correctly to prevent hashing the incorrect data. For example, function was called without the keyword argument (function(), instead of function(data=data)).

However, the current logic incorrectly checks the value available in the keyword argument, rather than the keyword argument was used. The following code leads to a RuntimeError when we should be serializing None->null just fine.

...

import random

@idemp_f(data_keyword_argument="key")
def echo(key: str = None):
    return random.randint(1, 1000000)

echo(key=None)

Changes

Please provide a summary of what's being changed

This PR corrects the logic and only raises RuntimeError if the keyword argument specified for hashing isn't in the list of keyword arguments available at the function call.

User experience

Please share what the user experience looks like before and after this change

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.

@heitorlessa heitorlessa requested a review from a team as a code owner October 28, 2022 09:54
@heitorlessa heitorlessa requested review from leandrodamascena and removed request for a team October 28, 2022 09:54
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 28, 2022
@boring-cyborg boring-cyborg bot added the tests label Oct 28, 2022
@heitorlessa heitorlessa linked an issue Oct 28, 2022 that may be closed by this pull request
2 tasks
@github-actions github-actions bot added the bug Something isn't working label Oct 28, 2022
@codecov-commenter
Copy link

codecov-commenter commented Oct 28, 2022

Codecov Report

Base: 99.35% // Head: 99.35% // No change to project coverage 👍

Coverage data is based on head (f6da33f) compared to base (87de70c).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1669   +/-   ##
========================================
  Coverage    99.35%   99.35%           
========================================
  Files          128      128           
  Lines         5908     5908           
  Branches       373      373           
========================================
  Hits          5870     5870           
  Misses          18       18           
  Partials        20       20           
Impacted Files Coverage Δ
...da_powertools/utilities/idempotency/idempotency.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

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

Nothing to change! LGTM!

@leandrodamascena leandrodamascena merged commit 2c26f84 into aws-powertools:develop Oct 28, 2022
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/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.

Feature request: Support raise_on_no_idempotency_key for idempotent_function
3 participants