-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
thantos
commented
Sep 18, 2023
•
edited
Loading
edited
- 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.
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 | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
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).
return assertNever(item); | ||
}) | ||
); | ||
items.forEach((item) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For each?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't these promises?
There was a problem hiding this comment.
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).