Skip to content

Commit 4ad3786

Browse files
committed
fix(core): Use a savepoint for the duplicate-translation insert retry
1 parent 9510965 commit 4ad3786

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

packages/core/src/service/helpers/translatable-saver/translation-differ.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,16 @@ export class TranslationDiffer<Entity extends Translatable & { id: ID }> {
6969
(translation as any).baseId = entity.id;
7070
let newTranslation: any;
7171
try {
72-
newTranslation = await this.connection
73-
.getRepository(ctx, this.translationCtor)
74-
.save(translation as any);
72+
// Run the insert in a savepoint (nested transaction). On Postgres, a unique
73+
// constraint violation aborts the entire enclosing transaction, which would
74+
// otherwise make the fallback queries below fail with "current transaction is
75+
// aborted" instead of recovering. Rolling back just the savepoint keeps the
76+
// outer transaction (shared with the rest of this request) healthy.
77+
newTranslation = await this.connection.withTransaction(ctx, transactionCtx =>
78+
this.connection
79+
.getRepository(transactionCtx, this.translationCtor)
80+
.save(translation as any),
81+
);
7582
} catch (err: any) {
7683
if (!isUniqueConstraintViolationError(err)) {
7784
throw new InternalServerError(err.message);

0 commit comments

Comments
 (0)