Description
When annotating functions via @idempotent_function, the wrapped function's name will not go into the hash computation; instead, only the payload and an environment-specific (but not function-specific) function name is assumed.
This causes idempotency to break in certain cases.
Expected Behavior
When two distinct functions which accept the very same payload as parameters are wrapped using @idempotent_function, invocation of one function should not affect invocation of the other function.
Current Behavior
Only the payload is considered.
The culprit appears to be
generated_hash = self._generate_hash(data=data)
function_name = os.getenv(constants.LAMBDA_FUNCTION_NAME_ENV, "test-func")
(lines 180-181) in persistence/base.py
. One can clearly see that only the environment variable or "test-func" is assumed - but that is - of course - not specific to the actual function being wrapped.
So in short, the library currently only really distinguishes by payload and not be function name, hence causing the aforementioned behaviour.
Possible Solution
Pass on the wrapped function's name and use it for the return value of _get_hashed_idempotency_key
.
Steps to Reproduce (for bugs)
def test():
myIdempotentFunc(product = "bananas")
anotherIdempotentFunc(product="bananas")
return {}
@idempotent_function(data_keyword_argument="product", persistence_store=dynamodb)
def myIdempotentFunc(product):
print("I got invoked with {product}".format(product = product))
return None
@idempotent_function(data_keyword_argument="product", persistence_store=dynamodb)
def anotherIdempotentFunc(product):
print("I will never get invoked; someone stole my payload :(".format(product = product))
return None
This only prints myIdempotentFunc's output, so anotherIdempotentFunc never gets invoked.
Environment
Using "aws-lambda-powertools==1.22.0" on Python 3.9.7
Thank you in advance!