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

[BUG] The "create" function under aws-python-http-api-with-pynamodb is not idempotent #659

Closed
Nsupyq opened this issue Nov 3, 2021 · 0 comments

Comments

@Nsupyq
Copy link
Contributor

Nsupyq commented Nov 3, 2021

The function create under aws-python-http-api-with-pynamodb example is not idempotent and may create multiple extra todos.

a_todo = TodoModel(todo_id=str(uuid.uuid1()),
                   text=data['text'],
                   checked=False)

a_todo.save()

The todo_id is randomly generated. Thus, when the function fails after the new todo is saved, the function will be retried and create a new todo again with a different todo_id. Similar issue exists in aws-python-rest-api-with-dynamodb/todos.

This can be fixed by making the function idempotent. We can use the awsRequestId to be todo_id. This is a unique identifier provided by AWS Lambda and is the same in retries. Then the function will create only one new todo. Another way to fix it is requiring the client to provide a parameter to be todo_id. The client can generate such an identifier via uuid API.

@Nsupyq Nsupyq closed this as completed Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant