Explorar o código

fix(core): Fix edge case FK error when creating new Collections

Fixes #1215
Michael Bromley %!s(int64=4) %!d(string=hai) anos
pai
achega
160f457c8b
Modificáronse 1 ficheiros con 5 adicións e 2 borrados
  1. 5 2
      packages/core/src/service/services/collection.service.ts

+ 5 - 2
packages/core/src/service/services/collection.service.ts

@@ -613,7 +613,10 @@ export class CollectionService implements OnModuleInit {
             return this.rootCollection;
             return this.rootCollection;
         }
         }
 
 
-        const rootTranslation = await this.connection.getRepository(ctx, CollectionTranslation).save(
+        // We purposefully do not use the ctx in saving the new root Collection
+        // so that even if the outer transaction fails, the root collection will still
+        // get persisted.
+        const rootTranslation = await this.connection.getRepository(CollectionTranslation).save(
             new CollectionTranslation({
             new CollectionTranslation({
                 languageCode: this.configService.defaultLanguageCode,
                 languageCode: this.configService.defaultLanguageCode,
                 name: ROOT_COLLECTION_NAME,
                 name: ROOT_COLLECTION_NAME,
@@ -622,7 +625,7 @@ export class CollectionService implements OnModuleInit {
             }),
             }),
         );
         );
 
 
-        const newRoot = await this.connection.getRepository(ctx, Collection).save(
+        const newRoot = await this.connection.getRepository(Collection).save(
             new Collection({
             new Collection({
                 isRoot: true,
                 isRoot: true,
                 position: 0,
                 position: 0,