Skip to content
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

Merged
merged 12 commits into from
Oct 25, 2022

Conversation

Marc-Roig
Copy link
Contributor

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:

  • An entity with loaded components.
  • An entity with an id.

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

@Marc-Roig Marc-Roig added source: core:strapi Source is core/strapi package pr: fix This PR is fixing a bug labels Oct 11, 2022
@Marc-Roig Marc-Roig added this to the 4.4.4 milestone Oct 11, 2022
@Marc-Roig Marc-Roig self-assigned this Oct 11, 2022
@Marc-Roig Marc-Roig changed the title filter empty components when deleting entity Fix bulk delete when entity has empty components Oct 11, 2022
@codecov
Copy link

codecov bot commented Oct 11, 2022

Codecov Report

Base: 58.71% // Head: 50.24% // Decreases project coverage by -8.47% ⚠️

Coverage data is based on head (f367352) compared to base (d905044).
Patch coverage: 26.66% of modified lines in pull request are covered.

❗ Current head f367352 differs from pull request most recent head d58963e. Consider uploading reports for the commit d58963e to get more accurate results

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     
Flag Coverage Δ
front ?
unit 50.24% <26.66%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...e/strapi/lib/services/entity-service/components.js 22.29% <8.33%> (+0.58%) ⬆️
...s/core/strapi/lib/services/entity-service/index.js 63.26% <100.00%> (+0.25%) ⬆️
...c/components/EditAssetDialog/ReplaceMediaButton.js
...plicationInfosPage/components/LogoInput/reducer.js
...issions/utils/formatContentTypesPermissionToAPI.js
...ore/admin/admin/src/components/GuidedTour/index.js
...in/src/components/BulkMoveDialog/BulkMoveDialog.js
...sPage/pages/Users/utils/validations/users/index.js
...min/src/content-manager/utils/createDefaultForm.js
...ckages/core/upload/admin/src/utils/urlYupSchema.js
... and 1034 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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -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);
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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 👍

Copy link
Contributor

@jhoward1994 jhoward1994 left a 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?

@Marc-Roig
Copy link
Contributor Author

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.
I had to add a default {} value for for the loadComponents parameter

In the deleteComponents function the desired behaviour is to load the components (which is the default when not passing anything)

And no idea how to leave a comment on an unmodified line :/

@jhoward1994 jhoward1994 self-requested a review October 13, 2022 11:51
@jhoward1994
Copy link
Contributor

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. I had to add a default {} value for for the loadComponents parameter

In the deleteComponents function the desired behaviour is to load the components (which is the default when not passing anything)

And no idea how to leave a comment on an unmodified line :/

Nice, it works well for me now 🙂

jhoward1994
jhoward1994 previously approved these changes Oct 13, 2022
(await strapi.query(uid).load(entityToDelete, attributeName));
if (!value && loadComponents) {
value = await strapi.query(uid).load(entityToDelete, attributeName);
}
Copy link
Contributor

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.

Copy link
Contributor Author

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
@Convly Convly modified the milestones: 4.4.4, 4.4.5, 4.4.6 Oct 19, 2022
@dkryvi
Copy link

dkryvi commented Oct 25, 2022

Hello, any updates in this pull request? It's a critical issue for our project

@Marc-Roig
Copy link
Contributor Author

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

@dkryvi
Copy link

dkryvi commented Oct 25, 2022

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 :)

Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :) well done

@Marc-Roig Marc-Roig merged commit 191b64d into main Oct 25, 2022
@Marc-Roig Marc-Roig deleted the fix/bulk-delete-error-no-compos branch October 25, 2022 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix This PR is fixing a bug source: core:strapi Source is core/strapi package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bulk delete from admin interface isn't working
5 participants