Question about error in Ecto Transaction with Multi

In the run docs it is written that I need return {:error, value} to rollback, if I a return exit/1 or a exception, also rollback in the same way or I need use try/catch and return {:error, value}?

2 Likes

Ecto.Repo — Ecto v3.11.1 is where it is actually run from, and as you can see there it states that:

In case of any errors the transaction will be rolled back and {:error, failed_operation, failed_value, changes_so_far} will be returned.

Specifically only in the case of success will it be committed, if it returns an error, errors, fails in any other way, system dies, whatever, then it will rollback.

3 Likes