medusa: Unable to delete a category!
Describe the bug
Getting 500 Error when sending a request to delete a Category.
System information
Node.js version: v 20.4.0 Database: postgres://localhost/medusa-starter-default Operating system: macOS 10.15.7 Browser (if relevant): Chrome 120 on macOS (Ventura)
Screenshots
Code snippets
/* delete categories */
export async function deleteAllCategoriesFromAPI() {
const allCategories = await medusa.admin.productCategories
.list()
.then(({ product_categories, limit, offset, count }) => {
console.log(
"There are: ",
product_categories.length,
" product categories"
);
return product_categories;
});
allCategories.forEach(async (category) => {
await medusa.admin.productCategories
.delete(category.id)
.then(({ id, object, deleted }) => {
console.log(`Category ${id} is deleted!`);
});
});
}
Additional context
I guess the problem should be specific to Categories Entities, because deleting Products work pretty fine. Getting Categories also works. The problem is with deleting them.
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Comments: 18 (10 by maintainers)
yes, at-least for now until the issue is resolved. forEach loop does not wait for all the promises in the iteration to be resolved. for loop on the other hand does.
Finally works! Thank you so much for help! Now the problem with corrupted ranks in my db is not an issue anymore, only if I will have another project installed, is that correct? Or you’ll fix the problem so even with a new project the problem will not persist?
Categories are deleted
All good, looks like the rank was indeed corrupted.
Run this in psql first:
and then try with the updated code:
@vasilemidrigan you need to put a semi colon in the end in psql
select id, name, rank, parent_category_id from product_category;
Thanks, can you run this on your db and show the results?
select id, name, rank, parent_category_id from product_category
. The rank might’ve been corrupted.