From cf67b12b3f21bf700140b73f83f63e37de0f7fed Mon Sep 17 00:00:00 2001 From: Marc-Roig Date: Tue, 11 Oct 2022 15:37:55 +0200 Subject: [PATCH] filter empty components when deleting entity --- .../strapi/lib/services/entity-service/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/core/strapi/lib/services/entity-service/index.js b/packages/core/strapi/lib/services/entity-service/index.js index 54277520c3..5425c7a64e 100644 --- a/packages/core/strapi/lib/services/entity-service/index.js +++ b/packages/core/strapi/lib/services/entity-service/index.js @@ -214,10 +214,14 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator }) return null; } - const componentsToDelete = await getComponents(uid, entityToDelete); + const componentsToDelete = await getComponents(uid, entityToDelete).then((x) => + _.omitBy(_.isNill, x) + ); await db.query(uid).delete({ where: { id: entityToDelete.id } }); - await deleteComponents(uid, { ...entityToDelete, ...componentsToDelete }); + if (!_.isEmpty(componentsToDelete)) { + await deleteComponents(uid, { ...entityToDelete, ...componentsToDelete }); + } await this.emitEvent(uid, ENTRY_DELETE, entityToDelete); @@ -238,11 +242,15 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator }) } const componentsToDelete = await Promise.all( - entitiesToDelete.map((entityToDelete) => getComponents(uid, entityToDelete)) + entitiesToDelete.map((entityToDelete) => + getComponents(uid, entityToDelete).then((x) => _.omitBy(_.isNill, x)) + ) ); const deletedEntities = await db.query(uid).deleteMany(query); - await Promise.all(componentsToDelete.map((compos) => deleteComponents(uid, compos))); + await Promise.all( + componentsToDelete.map((compos) => !_.isEmpty(compos) && deleteComponents(uid, compos)) + ); // Trigger webhooks. One for each entity await Promise.all(entitiesToDelete.map((entity) => this.emitEvent(uid, ENTRY_DELETE, entity)));