-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bulk delete when entity has empty components #14600
Conversation
Codecov ReportBase: 58.71% // Head: 50.24% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #14600 +/- ##
==========================================
- Coverage 58.71% 50.24% -8.48%
==========================================
Files 1321 279 -1042
Lines 31981 9687 -22294
Branches 5960 2109 -3851
==========================================
- Hits 18777 4867 -13910
+ Misses 11344 3977 -7367
+ Partials 1860 843 -1017
Flags with carried forward coverage won't be shown. Click here to find out more. Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@@ -217,7 +217,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator }) | |||
const componentsToDelete = await getComponents(uid, entityToDelete); | |||
|
|||
await db.query(uid).delete({ where: { id: entityToDelete.id } }); | |||
await deleteComponents(uid, { ...entityToDelete, ...componentsToDelete }); | |||
await deleteComponents(uid, componentsToDelete); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In entityToDelete the id was not there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes! But it wasn't for the bulk delete.
I though it was going to complicate things doing this in the bulkDelete, when you have multiple entities.
So my proposal is to return the entity id in getComponents
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussing it with you I made the changes!
It didn't make sense to return the entity ID in getComponents
. Now we specify if we want to loadComponentss when calling deleteComponents
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
In my testing single deletion works but bulkDelete
is causing an error. I think it is caused by packages/core/strapi/lib/services/entity-service/components.js#L361
not passing the third argument to deleteComponents
p.s. do you know how to leave a PR comment on an unmodified line?
good call. In the And no idea how to leave a comment on an unmodified line :/ |
Nice, it works well for me now 🙂 |
(await strapi.query(uid).load(entityToDelete, attributeName)); | ||
if (!value && loadComponents) { | ||
value = await strapi.query(uid).load(entityToDelete, attributeName); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a non repeatable component case, if loadComponents
is true
and there is no relations, we would load twice no? Line 286 and there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right. This could be removed.
it would load it twice for repeatable components
Hello, any updates in this pull request? It's a critical issue for our project |
Hello, I will try to push this so it is ready for next release |
Thank you. We'are waiting :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :) well done
What does it do?
Fix #14384
Why is it needed?
Deleting an entity with empty components was throwing an error.
deleteComponents
function expects one of the two:When components were empty, the first case was not met, so the function was expecting the entity with an id, which we were not passing. So 💥
How to test it?
Delete or bulk delete an entity and you should not see any error in the console.
Related issue(s)/PR(s)
#14384