aws-powertools / powertools-lambda-python

A developer toolkit to implement Serverless best practices and increase developer velocity.
https://docs.powertools.aws.dev/lambda/python/latest/
MIT No Attribution
2.89k stars 397 forks source link

Feature request: Support `raise_on_no_idempotency_key` for `idempotent_function` #1663

Closed dmwesterhoff closed 2 years ago

dmwesterhoff commented 2 years ago

Use case

Trying to use idempotent_function in an "optional" manner. Example:

import random

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

When called like echo(key=None) will raise RuntimeError, even when raise_on_no_idempotency_key is set to False

Solution/User Experience

Unless there is good reason not to respect the IdempotencyConfig.raise_on_no_idempotency_key value. Perhaps adding a similar parameter to idempotent_function like raise_on_no_data_keyword_argument or something to that effect.

Alternative solutions

No response

Acknowledgment

heitorlessa commented 2 years ago

Hey @dmwesterhoff could you post the full stack trace, please?

That seems like an issue actually more than a feature request - a full error will help speed up the diagnostics tomorrow.

Thanks a lot for flagging this!!

heitorlessa commented 2 years ago

Sending from mobile, excuse me from verbosity and typos

It's a bug! It was meant to be a guard against a keyword argument not being present (L137).

This should be a check on whether the data kwarg exists in kwargs - accidentally, this is getting the value, and checking if it's falsy. This means even key=False would fail here (no good!).

As it's late here (8:48pm), I can make the fix tomorrow and cut a release with other merged enhancements -- if you have the bandwidth, please feel free to send a PR and I can review & expedite tomorrow.

https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/aws_lambda_powertools/utilities/idempotency/idempotency.py

heitorlessa commented 2 years ago

@leandrodamascena need your review to this bugfix PR to add to today's release.

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY 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 tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] commented 2 years ago

This is now released under 2.1.0 version!

dmwesterhoff commented 2 years ago

Sorry for late reply, just seeing this now -- I was unsure of if this was unintended side effect (bug) or a feature :). Thanks for the swift resolution, much appreciated.