Calling Developers!
We are reenergizing our code contribution process! Learn More

Deleting a category

renate.boevink
renate.boevink Product Owner @ Zolemba Spryker Customer Posts: 9 πŸ§‘πŸ»β€πŸš€ - Cadet

I'm trying to delete a category via ZED - category - delete

But then I get this message: Unable to execute statement [DELETE FROM spy_category WHERE spy_category.id_category=:p1]
There is no futher information about the why. Would think there is still some reference to that specific category. But on what places should I think of? Usage in navigation / CMS pages / Product linking?

Would be nice to have just some more specific information.

Best Answers

  • christiankilb
    christiankilb Software Architect & Technical Lead Posts: 7 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited September 2023 Answer βœ“

    What I do in such cases is to copy-paste the query and run it manually in my database tool. This will give me a better error message.
    You may also have a look into \Propel\Runtime\ActiveQuery\QueryExecutor\AbstractQueryExecutor::handleStatementException

    If the debug mode is not enabled, Propel will not add the actual database error to the logged message. Afair debug mode is never enabled in Spryker by default, even not in local environment.

    If I'm allowed to take a wild guess, your problem is most likely foreign key relations. There are entities in other tables that relate to the category entities. You are not allowed to delete categories until all the relations were deleted before.

    Most database systems including MySQL, and Propel, supports cascading. So in theory you could define your related entities to be automatically deleted if the parent entity is deleted:

    But usually Spryker does not make use of this and you have to delete the entities via PHP first.

  • renate.boevink
    renate.boevink Product Owner @ Zolemba Spryker Customer Posts: 9 πŸ§‘πŸ»β€πŸš€ - Cadet
    Answer βœ“

    Found it via debugging. Apparently I have some category filters active. The internal error message was about the constraint with the product category filter table.

    Removing those filters (back to default in zed) was the key

Answers

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,005 βš–οΈ - Guardians (admin)

    Heyhey,

    I took a look at my local environment with the ootb b2b-demo-shop 202307.0 installed.

    I can not reproduce this. I think you do not get more information because it is a fatal error which should not happen.

    If I look through the code it seems that error you are describing is happening when the specified category should be deleted in the database. So I assume at that point it is already deleted (and because of exception rolled-back) or some read/write problem.

    Have a look at vendor/spryker/category/src/Spryker/Zed/Category/Business/Deleter/CategoryDeleter.php - all of the logic is executed transactional. so maybe some plugin is deleting that category already and once $this->categoryEntityManager->deleteCategory($idCategory); is called you get the exception.

    Hope this helps you to debug further. Let me know once you found the problem :)

    All the best,

    Florian

  • christiankilb
    christiankilb Software Architect & Technical Lead Posts: 7 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited September 2023 Answer βœ“

    What I do in such cases is to copy-paste the query and run it manually in my database tool. This will give me a better error message.
    You may also have a look into \Propel\Runtime\ActiveQuery\QueryExecutor\AbstractQueryExecutor::handleStatementException

    If the debug mode is not enabled, Propel will not add the actual database error to the logged message. Afair debug mode is never enabled in Spryker by default, even not in local environment.

    If I'm allowed to take a wild guess, your problem is most likely foreign key relations. There are entities in other tables that relate to the category entities. You are not allowed to delete categories until all the relations were deleted before.

    Most database systems including MySQL, and Propel, supports cascading. So in theory you could define your related entities to be automatically deleted if the parent entity is deleted:

    But usually Spryker does not make use of this and you have to delete the entities via PHP first.

  • renate.boevink
    renate.boevink Product Owner @ Zolemba Spryker Customer Posts: 9 πŸ§‘πŸ»β€πŸš€ - Cadet

    It is indeed a constraint with spy_category_attribute.

    But that table will always be filled. Wouldn't think all the data should first be deleted manually before removing the category?

  • renate.boevink
    renate.boevink Product Owner @ Zolemba Spryker Customer Posts: 9 πŸ§‘πŸ»β€πŸš€ - Cadet
    Answer βœ“

    Found it via debugging. Apparently I have some category filters active. The internal error message was about the constraint with the product category filter table.

    Removing those filters (back to default in zed) was the key