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

Better database exception handling within a transaction #639

Closed
qianl15 opened this issue Oct 7, 2024 · 1 comment
Closed

Better database exception handling within a transaction #639

qianl15 opened this issue Oct 7, 2024 · 1 comment

Comments

@qianl15
Copy link
Member

qianl15 commented Oct 7, 2024

The issue is that if a transaction was aborted due to any database issue, then the @Transaction function would lose its current transaction context and cannot properly proceed. The error will always be:

INSERT INTO dbos.transaction_outputs (workflow_uuid, function_id, output, txn_id, txn_snapshot, created_at) VALUES ($1, $2, $3, (select pg_current_xact_id_if_assigned()::text), $4, $5) RETURNING txn_id; - current transaction is aborted, commands ignored until end of transaction block

Issues reported from our user:

  • Be able to handle exceptions in the @transaction - not possible right now
  • The error is logged even when it's handled. That is also not desirable
  • A @transaction that is also a @GETAPI will fail even if the error is handled

Potential solution: when a transaction is aborted but there is some subsequent code to handle it, restart a new transaction for it.

@qianl15
Copy link
Member Author

qianl15 commented Oct 9, 2024

As we discussed in the team, we think the best solution is to provide a better error message: #640

If a transaction is aborted, then the function must throw an error. Error handling can be done outside of transactions. The reason is that for an aborted transaction, the current transaction connection to the database is aborted and cannot run any further commands. So there's no point to handle the error and continue with processing.

@qianl15 qianl15 closed this as completed Oct 9, 2024
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