@@ -103,7 +103,11 @@ export async function installPackage(options: {
103103 // delete the previous version's installation's SO kibana assets before installing new ones
104104 // in case some assets were removed in the new version
105105 if ( installedPkg ) {
106- await deleteKibanaSavedObjectsAssets ( savedObjectsClient , installedPkg . attributes . installed ) ;
106+ try {
107+ await deleteKibanaSavedObjectsAssets ( savedObjectsClient , installedPkg . attributes . installed ) ;
108+ } catch ( err ) {
109+ // some assets may not exist if deleting during a failed update
110+ }
107111 }
108112
109113 const [ installedKibanaAssets , installedPipelines ] = await Promise . all ( [
@@ -207,33 +211,20 @@ export async function saveInstallationReferences(options: {
207211 toSaveAssetRefs,
208212 toSaveESIndexPatterns,
209213 } = options ;
210- const installation = await getInstallation ( { savedObjectsClient, pkgName } ) ;
211- const savedAssetRefs = installation ?. installed || [ ] ;
212- const toInstallESIndexPatterns = Object . assign (
213- installation ?. es_index_patterns || { } ,
214- toSaveESIndexPatterns
215- ) ;
216-
217- const mergeRefsReducer = ( current : AssetReference [ ] , pending : AssetReference ) => {
218- const hasRef = current . find ( c => c . id === pending . id && c . type === pending . type ) ;
219- if ( ! hasRef ) current . push ( pending ) ;
220- return current ;
221- } ;
222214
223- const toInstallAssetsRefs = toSaveAssetRefs . reduce ( mergeRefsReducer , savedAssetRefs ) ;
224215 await savedObjectsClient . create < Installation > (
225216 PACKAGES_SAVED_OBJECT_TYPE ,
226217 {
227- installed : toInstallAssetsRefs ,
228- es_index_patterns : toInstallESIndexPatterns ,
218+ installed : toSaveAssetRefs ,
219+ es_index_patterns : toSaveESIndexPatterns ,
229220 name : pkgName ,
230221 version : pkgVersion ,
231222 internal,
232223 } ,
233224 { id : pkgName , overwrite : true }
234225 ) ;
235226
236- return toInstallAssetsRefs ;
227+ return toSaveAssetRefs ;
237228}
238229
239230async function installKibanaSavedObjects ( {
0 commit comments