Sylius version affected: 1.6.1
Description
We changed our taxon fixtures and now we are getting random Error: Nesting level too deep - recursive dependency?" at /calida/shop/vendor/gedmo/doctrine-extensions/lib/Gedmo/Sortable/SortableListener.php line 471 errors. This happens when comparing two Taxon objects.
Steps to reproduce
This is the relevant fixture configuration we added
sylius_fixtures:
suites:
default:
fixtures:
taxon:
options:
custom:
- name: root
code: root
translations:
en_US:
name: Root
children:
- code: men
name: Men
slug: men
translations:
en_US:
name: Men
children:
- code: mens_jeans
name: Jeans
slug: men/jeans
translations:
en_us:
name: Jeans
- code: mens_tops
name: Tops
slug: men/tops
translations:
en_US:
name: Tops
- code: women
name: Women
slug: women
translations:
en_US:
name: Women
children:
- code: womens_jeans
name: Jeans
slug: women/jeans
translations:
en_US:
name: Jeans
- code: womens_tops
name: Tops
slug: women/tops
translations:
en_US:
name: Tops
- code: dresses
name: Dresses
slug: women/dresses
translations:
en_US:
name: Dresses
Obviously posting full reproducing example is hard, but this happens when hitting product edit endpoint and changing mainTaxon
Possible Solution
Consider implementing Doctrine\Common\Comparable interface on your Taxon model to avoid weak comparison check.
This error is also happening when removing ProductTaxon using EntityManager. Basically I have a function to delete ProductTaxon in a loop for multiple products, this doesn't happen all the time, and I am not sure what triggers this error either.
We solved this by implementing Doctrine\Common\Comparable on our Taxon model. Ideally Sylius itself would implement it though.
Thanks @ostrolucky Confirmed that this does solve the issue
I'm also experiencing this problem on ProductTaxon. If I have only one product taxon, I can delete it successfully, but when I have two product taxon and try to remove one of them, the error is triggered.
Hello,
I got the same issue, I also think Sylius should implement Doctrine\Common\Comparable in all ressources.
@Zales0123, should we change Potential Bug to Bug ?
Thanks
Faced it too...
And I believe all resources should implement Comparable out of the box, as SortableListener have this line which will compare all object's fields one by one:
$matches = $gr == $value;
And will reach nesting level limit almost in 100% cases.
I'm using the version 1.7 of Sylius and I faced the same error when edition a Product and changing the selection for the Taxons.
@igormukhingmailcom and/or @ostrolucky would one of you be able to share what you did to fix this problem for now?
Thank you!
UPD: Fixed implementation. Latest 1.7.* already have this fix.
use Doctrine\Common\Comparable;
class Taxon extends BaseTaxon implements Comparable
{
/**
* Its a workaround
*
* @see https://github.com/Sylius/Sylius/issues/10797
*
* @param mixed $other
*
* @return int
*/
public function compareTo($other)
{
return $this->code === $other->getCode() ? 0 : 1;
}
}
@igormukhingmailcom Thank you for your help here, I will try this out 👍
Fixed by #11329.