kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
9.9k stars 249 forks source link

Attempting to rollback a connection that fails to get created #952

Open mdnorman opened 3 months ago

mdnorman commented 3 months ago

At this line, the beginTransaction call could fail, throwing an error that gets caught on line 570. The issue we are running into is that rollbackTransaction then gets called on a transaction that's not created yet. In the driver we're using, rolling back a transaction that's not created yet is considered an error.

I could go either way on this one, so is it a bug in the driver code that rollbackTransaction shouldn't throw an error if it's not in a transaction yet, or is it a bug to call rollbackTransaction when the transaction hasn't been created yet.

If the former, I'll go open an issue against the driver to put a fix in. If it's the latter, then I'm hoping it can get fixed here.

koskimas commented 3 months ago

Nice catch (pun intended)! This should be fixed in Kysely.

On the other hand, beginTransaction can do multiple things. For example mysql creates a transaction and sets the isolation level using a separate query. If the second query fails, we still need to roll back the transaction.

But leaving this up to the driver seems risky too.