question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incomplete input for hash function for @idempotent_function

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
heitorlessacommented, Dec 7, 2021

merged - tagging for the next release hopefully this Friday

1reaction
michaelbrewercommented, Dec 4, 2021

@heitorlessa @dispyfree - a basic fix for this in my PR (https://github.com/awslabs/aws-lambda-powertools-python/pull/869). I am just going to add a good unit test to reproduce the issue as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there an idempotent hash function? - Stack Overflow
I'd like the user to be able to authenticate with this hashed password. Rather than simply trying the authentication twice (once assuming the ......
Read more >
Structured Streaming Programming Guide - Apache Spark
First, we have to import the necessary classes and create a local SparkSession, the starting point of all functionalities related to Spark. Scala;...
Read more >
Two Buckets and a Lambda: a pattern for file processing
For each input file, I call the process() function followed by the archive() function. This pair of calls is wrapped in a try-catch...
Read more >
Nixpkgs 22.11 manual - NixOS
First, if an overlays argument to the Nixpkgs function itself is given, ... mkDerivation to process input arguments, as well as the fact...
Read more >
perlapi - autogenerated documentation for the perl public API
The returned hash pointer is in general not the same as the hash pointer that was passed in. The input hash is consumed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found