Skip to content

Bug: using an array for EventKeyJMESPath in idempotency module causes an error #1419

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

Closed
jeromevdl opened this issue Sep 5, 2023 · 1 comment · Fixed by #1420
Closed

Bug: using an array for EventKeyJMESPath in idempotency module causes an error #1419

jeromevdl opened this issue Sep 5, 2023 · 1 comment · Fixed by #1420
Assignees
Labels
bug Something isn't working priority:2 High - core feature or affects 60% of the users size/S

Comments

@jeromevdl
Copy link
Contributor

What were you trying to accomplish?

When using an array to select multiple fields in the payload to build the idempotency key, an exception is thrown: No data found to create a hashed idempotency key

Expected Behavior

When using an array for EventKeyJMESPath (e.g. "[field1, field2]") to select multiple elements in a payload, idempotency module should take the fields specified in the array.

Current Behavior

An error is thrown: No data found to create a hashed idempotency key (code here)

Possible Solution

In BasePersistenceStore, replace:

    private boolean isMissingIdemPotencyKey(JsonNode data) {
        if (data.isContainerNode()) {
            Stream<Map.Entry<String, JsonNode>> stream =
                    StreamSupport.stream(Spliterators.spliteratorUnknownSize(data.fields(), Spliterator.ORDERED),
                            false);
            return stream.allMatch(e -> e.getValue().isNull());
        }
        return data.isNull();
    }

with (note the data.elements instead of fields):

    private boolean isMissingIdemPotencyKey(JsonNode data) {
        if (data.isContainerNode()) {
            Stream<JsonNode> stream =
                    StreamSupport.stream(Spliterators.spliteratorUnknownSize(data.elements(), Spliterator.ORDERED),
                            false);
            return stream.allMatch(JsonNode::isNull);
        }
        return data.isNull();
    }

Environment

  • Powertools for AWS Lambda (Java) version used: 1.17.0
  • Packaging format (Layers, Maven/Gradle): maven
  • AWS Lambda function runtime: Java17
  • Debugging logs

How to enable debug mode**

{
    "timestamp": "2023-09-05T16:02:26.409+0000UTC",
    "instant": {
        "epochSecond": 1693929746,
        "nanoOfSecond": 409000000
    },
    "thread": "main",
    "level": "ERROR",
    "loggerName": "com.amazonaws.powertools.workshop.Module1Handler",
    "message": "An unexpected error occurred",
    "thrown": {
        "message": "No data found to create a hashed idempotency key",
        "name": "software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyKeyException",
        "extendedStackTrace": [
            {
                "class": "software.amazon.lambda.powertools.idempotency.persistence.BasePersistenceStore",
                "method": "getHashedIdempotencyKey",
                "file": "BasePersistenceStore.java",
                "line": 247
            },
            {
                "class": "software.amazon.lambda.powertools.idempotency.persistence.BasePersistenceStore",
                "method": "saveInProgress",
                "file": "BasePersistenceStore.java",
                "line": 150
            },
            {
                "class": "software.amazon.lambda.powertools.idempotency.internal.IdempotencyHandler",
                "method": "processIdempotency",
                "file": "IdempotencyHandler.java",
                "line": 90
            },
            {
                "class": "software.amazon.lambda.powertools.idempotency.internal.IdempotencyHandler",
                "method": "handle",
                "file": "IdempotencyHandler.java",
                "line": 72
            },
            {
                "class": "software.amazon.lambda.powertools.idempotency.internal.IdempotentAspect",
                "method": "around",
                "file": "IdempotentAspect.java",
                "line": 79
            },
@jeromevdl jeromevdl added bug Something isn't working triage labels Sep 5, 2023
@jeromevdl jeromevdl added size/S priority:2 High - core feature or affects 60% of the users and removed triage labels Sep 5, 2023
@jeromevdl jeromevdl self-assigned this Sep 5, 2023
@jeromevdl jeromevdl moved this from Triage to Working on it in Powertools for AWS Lambda (Java) Sep 5, 2023
jeromevdl added a commit that referenced this issue Sep 5, 2023
jeromevdl added a commit that referenced this issue Sep 5, 2023
@scottgerring scottgerring linked a pull request Sep 7, 2023 that will close this issue
6 tasks
jeromevdl added a commit that referenced this issue Sep 11, 2023
@jeromevdl jeromevdl reopened this Sep 11, 2023
@jeromevdl jeromevdl moved this from Working on it to Coming soon in Powertools for AWS Lambda (Java) Sep 11, 2023
@github-project-automation github-project-automation bot moved this from Coming soon to Working on it in Powertools for AWS Lambda (Java) Sep 11, 2023
@scottgerring scottgerring moved this from Working on it to Coming soon in Powertools for AWS Lambda (Java) Oct 9, 2023
jeromevdl added a commit that referenced this issue Oct 12, 2023
Copy link
Contributor

This is now released under 1.18.0 version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:2 High - core feature or affects 60% of the users size/S
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

1 participant