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

fix: transaction in a workflow transform error #450

Merged
merged 2 commits into from
Sep 19, 2023

Conversation

thantos
Copy link
Contributor

@thantos thantos commented Sep 18, 2023

  • BUG: Transaction in a workflow would error instead of returning a successful response
    • Bad change during the executor refactor that assumed the base transaction executor return an object with success/fail and not just an object.
  • BUG: In a transaction the condition operation would fail if the version was 0 (aka, should not exist yet).
    • This happens when a entity.get return undefined within a transaction and we want to assert that the item doesn't exist by the end of the transaction.
    • Root Cause: a EntityAttributeValueMap key was being created for expected version when the value was defined, but only used when defined or not 0.
    • Solution: Fixed the logic to match.
  • BUG: In Local, transaction could conflict when started at overlapping intervals.
    • This was because the local transaction assumed that the calls would be synchronous when there were not. The Logic is 1. validate all versions, 2. apply changes, but the validation may be invalid by feat: add copy to README #2 AND the lower level operations will re-assert the expected version logic before applying, failing.
    • Solution: TransactWrite only uses sync methods in local now, maintaining control through step 1 and 2.

Comment on lines -26 to +33
if (result.succeeded) {
return createEvent<TransactionRequestSucceeded>(
{
type: WorkflowEventType.TransactionRequestSucceeded,
result: result.output,
seq,
},
executionTime
);
} else {
return createEvent<TransactionRequestFailed>(
{
type: WorkflowEventType.TransactionRequestFailed,
error: "Transaction Failed",
message: "",
seq,
},
executionTime
);
}
return createEvent<TransactionRequestSucceeded>(
{
type: WorkflowEventType.TransactionRequestSucceeded,
result,
seq,
},
executionTime
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The executor returns the value (any), not the object with the success boolean. turning success: false is done in the nested executor because that logic is shared between the workflow and the normal transaction call now (before it was duplicated).

@thantos thantos requested a review from sam-goodwin September 18, 2023 22:31
return assertNever(item);
})
);
items.forEach((item) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For each?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these promises?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the problem was that they were promises and happening in "parallel" with other things (ex: other transactions).

So now the whole function is async (except for the response).

@thantos thantos merged commit e000bfc into main Sep 19, 2023
@thantos thantos deleted the sussman/fix/transact_ws_bug branch September 19, 2023 00:22
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

Successfully merging this pull request may close these issues.

2 participants