@@ -10,6 +10,7 @@ import ModelCardRevisionModel, { ModelCardRevisionDoc } from '../models/ModelCar
10
10
import { UserInterface } from '../models/User.js'
11
11
import { GetModelCardVersionOptions , GetModelCardVersionOptionsKeys , GetModelFiltersKeys } from '../types/enums.js'
12
12
import { isValidatorResultError } from '../types/ValidatorResultError.js'
13
+ import { isReplicaSet } from '../utils/database.js'
13
14
import { toEntity } from '../utils/entity.js'
14
15
import { BadReq , Forbidden , InternalError , NotFound } from '../utils/error.js'
15
16
import { convertStringToId } from '../utils/id.js'
@@ -224,16 +225,21 @@ export async function _setModelCard(
224
225
225
226
const revision = new ModelCardRevisionModel ( { ...newDocument , modelId, createdBy : user . dn } )
226
227
227
- const message = 'Unable to save model card revision'
228
- await mongoose . connection
229
- . transaction ( async function executeUpdate ( session ) {
230
- await revision . save ( { session } )
231
- await ModelModel . updateOne ( { id : modelId } , { $set : { card : newDocument } } , { session : session } )
232
- } )
233
- . catch ( ( error ) => {
234
- log . error ( 'Error when updating model card/revision. Transaction rolled back.' , error )
235
- throw InternalError ( message , { modelId } )
236
- } )
228
+ if ( await isReplicaSet ( ) ) {
229
+ await mongoose . connection
230
+ . transaction ( async function executeUpdate ( session ) {
231
+ await revision . save ( { session } )
232
+ await ModelModel . updateOne ( { id : modelId } , { $set : { card : newDocument } } , { session : session } )
233
+ } )
234
+ . catch ( ( error ) => {
235
+ const message = 'Unable to save model card revision'
236
+ log . error ( 'Error when updating model card/revision. Transaction rolled back.' , error )
237
+ throw InternalError ( message , { modelId } )
238
+ } )
239
+ } else {
240
+ await revision . save ( )
241
+ await ModelModel . updateOne ( { id : modelId } , { $set : { card : newDocument } } )
242
+ }
237
243
238
244
return revision
239
245
}
0 commit comments