Mark transaction as closed *only* after commit/rollback succeeds.
Previously, `open` on the transaction would be set to `false` prior to attempting
to commit or rollback the transaction. When the operation failed, for example, due
to a serialization failure with a serializable isolation level, this would leave
the transaction in an inconsistent state, where it thought it was closed but really
it was still open. The connection would then be returned to the connection pool with
a transaction depth of 1, causing a savepoint to be erroneously created the next time
a transaction was created for the connection.
By waiting to set `open` to `false` until the commit/rollback succeeds, a failure
to do either will result in us correctly rolling back the transaction when dropping
it, ensuring that the connection is returned to the pool with a transaction depth
of 0. Note that this is consistent with how `sqlx` handles transactions.
We attempted to write a test, but had a very difficult time forcing postgres to fail
to commit a transaction. We found that it would block our requests instead when creating
conflicting updates, and we couldn't find any information about when it blocks vs when
transaction commits fail.
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Nathan Sobo <nathan@zed.dev>
* feat: Introducing feature "sqlx-error"
Purpose of this feature is to not convert errors given from sqlx into strings to ease further analysis of the error and react to it accordingly. This implementation uses a feature switch and an additional error kind to avoid interfering with existing implementations without this feature enabled.
See discussion https://github.com/SeaQL/sea-orm/discussions/709
* fix: Align feature "sqlx-error" with merged Migration error kind
Due to the merge, an other error kind had been introduced and the DbErr became Eq and Clone, however Eq cannot easily be derived from, so I went back to PartialEq, and since the sqlx error does not implement clone, this was converted into an Arc, to allow cloning of the new kind too.
* fix: Repairing failing jobs
Several jobs had failed as I missed to correct the return values of a few methods in transaction.rs and had a wrong understanding of map_err at that point.
* feat: realigning with latest changes in sea-orm, different approach
Instead of the former approach to introduce a new error kind, now the existing error types get extended, for now only Exec and Query, because these are the most relevant for the requirement context.
Afterwards it might still be possible to add some further detail information.
See discussion https://github.com/SeaQL/sea-orm/discussions/709
* Update src/driver/sqlx_mysql.rs
Integrating fixes done by @Sculas
Co-authored-by: Sculas <contact@sculas.xyz>
* Update src/driver/sqlx_postgres.rs
Integrating fixes done by @Sculas
Co-authored-by: Sculas <contact@sculas.xyz>
* Update src/driver/sqlx_sqlite.rs
Integrating fixes done by @Sculas
Co-authored-by: Sculas <contact@sculas.xyz>
* feat: reworking feature with thiserror
Following the latest suggestions I changed the implementation to utilize `thiserror`.
Now there are more error kinds to be able to see the different kinds directly in src/error.rs
To ensure the behaviour is as expected, I also introduce a further test, which checks for a uniqueness failure.
Co-authored-by: Sculas <contact@sculas.xyz>
* Bump version of sqlx, sea-query, sea-schema, time and uuid
* PostgreSQL `u32` was wrapped in `Oid` (launchbadge/sqlx#1602)
* Update test cases
* Fix clippy warnings
* cargo fmt
* Fix clippy warnings
* Bump sea-schema to ^0.9.2
* Update test cases
* Pin on sea-query minor version