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

🪲 Running programs throws an error if logged in #5513

Merged
merged 9 commits into from
May 10, 2024
Merged

Conversation

rix0rrr
Copy link
Collaborator

@rix0rrr rix0rrr commented May 9, 2024

When logged in, we automatically save a program as the user runs it.

In a recent change, we update the program counter only when a program is modified from the example code. But we wrote the entire 'program' record back to the database in an update() call, which includes the id field; Dynamo does not allow including the id field in an update() call.

This is also not necessary: a DynamoDB update() call only needs to include the fields we actually want to change, and not any of the fields that are unchanged (this may even lead to a race condition if any of those fields were changed in between the read and update calls, we would undo the intermediate change again).

Instead, only update the is_modified field, and update the Dynamo abstraction layer to check for this error condition.

How to test

Log in, and run a program.

When logged in, we automatically save a program as the user runs it.

In a recent change, we update the program counter only when a program is
modified from the example code. But we wrote the entire 'program' record
back to the database in an `update()` call, which includes the `id`
field; Dynamo does not allow including the `id` field in an `update()`
call.

Instead, only update the `is_modified` field, and update the Dynamo
abstraction layer to check for this error condition.
@rix0rrr rix0rrr changed the title 🪲 Fix running programs when logged in 🪲 Running programs throws an error if logged in May 9, 2024
@rix0rrr
Copy link
Collaborator Author

rix0rrr commented May 9, 2024

@Annelein this should have thrown an error locally before deploying and running against an actual DynamoDB, so my apologies that it didn't. But also, update() is supposed to only get the fields you want to change, while put() should be used if you really want to overwrite all fields of an entire record (and delete all non-included fields).

# Insert or replace an entire record (all fields not part of this write are gone)
table.put(entire_record)

# Update a single field (all other fields remain unchanged)
table.update(record['id'], { 'field': 'new_value', 'another_field': 'another_value' })

update() is safe against concurrent updates(), while put() will just overwrite all fields (even if another request changed any of the fields in the mean time).

Copy link
Contributor

mergify bot commented May 10, 2024

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit eae44da into main May 10, 2024
12 checks passed
@mergify mergify bot deleted the fix-key-update branch May 10, 2024 12:23
Copy link
Contributor

mergify bot commented May 10, 2024

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

@Annelein
Copy link
Collaborator

@rix0rrr thank you for the feedback, fix and explanation! Really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants