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

Docs: Idempotency - Exception not affecting idempotency record sample example has python syntax errors #1216

Closed
michaelbrewer opened this issue May 18, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@michaelbrewer
Copy link
Contributor

Expected Behaviour

Handling exceptions - Exception not affecting idempotency record sample example should not have python syntax errors or missing imports.

Current Behaviour

This example have python syntax errors and missing imports

Screen Shot 2022-05-17 at 9 27 47 PM

Code snippet

def lambda_handler(event, context):
    # If an exception is raised here, no idempotent record will ever get created as the
    # idempotent function does not get called
    do_some_stuff()

    result = call_external_service(data={"user": "user1", "id": 5})

    # This exception will not cause the idempotent record to be deleted, since it
    # happens after the decorated function has been successfully called
    raise Exception


@idempotent_function(data_keyword_argument="data", config=config, persistence_store=dynamodb)
def call_external_service(data: dict, **kwargs):
    result = requests.post('http://example.com', json={"user": data['user'], "transaction_id": data['id']}
    return result.json()

Possible Solution

Fix python syntax errors like the PR #1119 , and deployed over here https://gyft.github.io/aws-lambda-powertools-python/latest/utilities/idempotency/#handling-exceptions

import requests

from aws_lambda_powertools.utilities.idempotency import DynamoDBPersistenceLayer, IdempotencyConfig, idempotent_function

dynamodb = DynamoDBPersistenceLayer(table_name="idem")
config = IdempotencyConfig(event_key_jmespath="order_id")


def lambda_handler(event, context):
    # If an exception is raised here, no idempotent record will ever get created as the
    # idempotent function does not get called
    do_some_stuff()

    result = call_external_service(data={"user": "user1", "id": 5})

    # This exception will not cause the idempotent record to be deleted, since it
    # happens after the decorated function has been successfully called
    raise Exception


@idempotent_function(data_keyword_argument="data", config=config, persistence_store=dynamodb)
def call_external_service(data: dict, **kwargs):
    result = requests.post("http://example.com", json={"user": data["user"], "transaction_id": data["id"]})
    return result.json()

Steps to Reproduce

  1. Go to https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/idempotency/#handling-exceptions
  2. Copy Exception not affecting idempotency record sample
  3. Code example should not be able to compile

AWS Lambda Powertools for Python version

latest

AWS Lambda function runtime

3.9

Packaging format used

PyPi

Debugging logs

N/A
@michaelbrewer michaelbrewer added bug Something isn't working triage Pending triage from maintainers labels May 18, 2022
@michaelbrewer michaelbrewer changed the title Bug: Idempotency - Idempotency - Exception not affecting idempotency record sample example has python syntax errors Bug: Idempotency - Exception not affecting idempotency record sample example has python syntax errors May 18, 2022
@sthulb sthulb changed the title Bug: Idempotency - Exception not affecting idempotency record sample example has python syntax errors Docs: Idempotency - Exception not affecting idempotency record sample example has python syntax errors May 18, 2022
@heitorlessa heitorlessa added documentation Improvements or additions to documentation and removed bug Something isn't working labels May 20, 2022
@sthulb sthulb closed this as completed Jun 14, 2022
@github-actions
Copy link
Contributor

Comments on closed issues are hard for our team to see.

@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants