Skip to content

Commit 544c69b

Browse files
committed
fix: Do not attempt to commit partial transactions on error
Committing partial transactions is a great way to induce data corruption by committing inconsistent data to the database. Transaction MUST always form a unit! Fortunately, this probably never mattered in practice as PostgreSQL will put transactions with failed commands into an *aborted* state, where the only valid subsequent in-transaction command is rolling back partially or completely: > […] Moreover, ROLLBACK TO is the only way to regain control of a transaction block that was put in aborted state by the system due to an error, short of rolling it back completely and starting again. https://www.postgresql.org/docs/current/tutorial-transactions.html So this “only” improves error messages and avoids an unnecessary round trip, not change application observable behaviour.
1 parent c7a64f3 commit 544c69b

1 file changed

Lines changed: 0 additions & 5 deletions

File tree

query/transaction.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ export class Transaction {
513513
return (await this.#executeQuery(query)) as QueryArrayResult<T>;
514514
} catch (e) {
515515
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
516-
await this.commit();
517516
throw new TransactionError(this.name, e);
518517
}
519518
throw e;
@@ -615,7 +614,6 @@ export class Transaction {
615614
return (await this.#executeQuery(query)) as QueryObjectResult<T>;
616615
} catch (e) {
617616
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
618-
await this.commit();
619617
throw new TransactionError(this.name, e);
620618
}
621619
throw e;
@@ -759,7 +757,6 @@ export class Transaction {
759757
await this.queryArray(`ROLLBACK ${chain_option ? "AND CHAIN" : ""}`);
760758
} catch (e) {
761759
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
762-
await this.commit();
763760
throw new TransactionError(this.name, e);
764761
}
765762
throw e;
@@ -858,7 +855,6 @@ export class Transaction {
858855
await savepoint.update();
859856
} catch (e) {
860857
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
861-
await this.commit();
862858
throw new TransactionError(this.name, e);
863859
}
864860
throw e;
@@ -878,7 +874,6 @@ export class Transaction {
878874
await savepoint.update();
879875
} catch (e) {
880876
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
881-
await this.commit();
882877
throw new TransactionError(this.name, e);
883878
}
884879
throw e;

0 commit comments

Comments
 (0)