File tree Expand file tree Collapse file tree
packages/core/src/service/helpers/translatable-saver Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments