Using the dev version of the module and the patch for Support for sub-entity cloning @ https://www.drupal.org/project/entity_clone/issues/2706639 we get the error "Fatal error: Maximum function nesting level of '256' reached, aborting!" when the entity has a Entity Reference field that references entities of the same content type.
The message also shows that it's looping around these functions
Drupal\entity_clone\EntityClone\Content\ContentEntityCloneFormBase->getRecursiveFormElement( ) .../ContentEntityCloneFormBase.php:89
Drupal\entity_clone\EntityClone\Content\ContentEntityCloneFormBase->getChildren( ) .../ContentEntityCloneFormBase.php:186
Drupal\entity_clone\EntityClone\Content\ContentEntityCloneFormBase->formElement( ) .../ContentEntityCloneFormBase.php:206
Drupal\entity_clone\EntityClone\Content\ContentEntityCloneFormBase->getRecursiveFormElement( ) .../ContentEntityCloneFormBase.php:89
Drupal\entity_clone\EntityClone\Content\ContentEntityCloneFormBase->getChildren( ) .../ContentEntityCloneFormBase.php:186
Drupal\entity_clone\EntityClone\Content\ContentEntityCloneFormBase->formElement( ) .../ContentEntityCloneFormBase.php:206
Seems that it's trying to clone entities within entities within entities which it probably shouldn't be doing.
Steps to duplicate:
1. Create a content type, save
2. Edit and add a Entity Reference field that references that same content type
3. Create a couple of nodes and edit and reference the other node
4. Try to clone and get this error
Not sure how to limit that recursive action or (right now) how to add the ability to not clone an Entity Reference field in the /admin/config/system/entity-clone settings page.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | 2945192_27.patch | 1.58 KB | cosmicdreams |
| #16 | 2945192-16.patch | 1.23 KB | flocondetoile |
| #14 | 2945192_14.patch | 2.04 KB | cosmicdreams |
| #12 | max-nesting-level-2945192-11.patch | 982 bytes | turtletrail |
| #10 | max-nesting-level-2945192-10.patch | 921 bytes | turtletrail |
Comments
Comment #2
farse commentedI'm experiencing this too.
Comment #3
Anonymous (not verified) commentedSame here.
Comment #4
bdanin commentedI just got this message as well with a newly nested paragraph
I'm using the patches as described in entity_clone/issues/2706639, comment #31
although, disabling entity_clone didn't solve anything, so I think this might be a problem of paragraphs referencing the same field inside a paragraph that's already referencing that field
I don't think this is related to entity_clone, at least not for me
full output of the error from the log:
Comment #5
Anonymous (not verified) commented@bdanin On which page do you receive the error? If it has nothing to do with entity clone, in your setup? Because I am getting it specifically on the entity clone page.
Comment #6
bdanin commentedFor me, this error happened on the view of the page where I had placed the paragraph.
Comment #7
cosmicdreams commentedI'm going to be looking into this in the coming week.
Comment #8
kamkejj commentedI think this is no longer an issue with the latest dev version. Haven't gotten the nesting error for this specific issue, but am getting it related to another use case.
Comment #9
kamkejj commentedAfter even more testing this issue still applies, with a entity reference to the same content type that are nodes. The recursion keeps iterating over the getChildren(ContentEntityInterface $referenced_entity) function until it errors out with the max nesting level.
This patch is a quick fix that works for our needs.
Comment #10
turtletrail commented#9 lead to me to the right direction, but in my case it was actually the media type that had to be skipped.
Patch that worked for me is attached, however as noticed before it's a temporal solution and proper fix is needed.
Comment #11
mallezieThe problem lies when we are getting in a loop when we end up referencing things we already references.
Simplest case to get into it.
Create a node, with a reference field, and reference to itself.
More complex / realistic case.
Node A referencing node B which has another reference again to node A.
A fix should keep track of the entities walked through in the recursive getRecursiveFormElement function, and break the loop when we encounter entities already referenced.
Comment #12
turtletrail commentedan addition to #10, there is also a taxonomy term that must be skipped from children cloning.
patch updated
once again, that is a temporary fix just to get things working.
A proper fix most likely should be based on what @mallezie has suggested.
Comment #13
cosmicdreams commentedAlthough these patches are great. For some of the sites that I find myself maintaining I still have an issue if the content structures were poorly structured. If someone introduces a circular reference the cloning of the content is doomed to fail as there is no protection in the way an entity is recursively cloned for circular references.
I'm thinking that perhaps I should create a separate issue for that.
Comment #14
cosmicdreams commentedAs I mentioned in my previous comment, I feel that better protection against circular references is needed in order for this issue to be complete. This patch does that, I believe. Well it works for me. Do you have time to review and let me know what you think?
Comment #15
socialnicheguru commentedComment #16
flocondetoileI met same issue when cloning a term, with a paragraph referencing a node, this node referencing same term
Patch #14 fix the issue.
Attached same patch clean up (removed break line added).
Comment #17
flocondetoileAs #16 is the same patch as #14, moving to RTBC
Comment #18
cosmicdreams commentedWe might have to hold here. With my patch I'm experiencing a overly aggressive cloning behavior. (cloning too much) . Diagnosing...
Comment #19
cosmicdreams commentedTwo issues reported:
1. When deleting a paragraph on a clone, the paragraph is deleted on the original content item.
2. When cloning an entity, lack of control of what gets cloned.
Comment #20
cosmicdreams commentedTurns out these issues might be related to how we told entity clone to handle it's cloning rather than this patch. Will finish that review today.
Side question: Does this solve the issue of properly cloning paragraphs instead of copying the target_id so that the paragraph reference exists in both nodes?
Comment #21
flocondetoile@cosmicdreams Cloning paragraphs have been solved by #2706639: Support for sub-entity cloning. If you have issue about this (and using entity clone to clone node with a lot paragraph, I don't have issues with), this is unrelated to the current issue and the fix.
I have done some manual tests and patch #16 fix well the infinite loop generated when building the form, if some parent entities are referenced too by children entities. I did not encounter side effects.
Comment #22
cosmicdreams commentedAgreed
Comment #23
acbramley commentedInstead of a drupal_static we should be using a class member variable instead. Also tests would be great!
Comment #24
nsciaccaThis patch is working well for me, except that on certain content types I'm running into Fatal Errors regarding max memory size. I didn't have these errors until apply the sub-entity patch so I assume it's all the recursing and nested fields. I have paragraphs within paragraphs and it gets complex. Anyone experiencing the same issue or have suggestions for where to look/optimize?
Some additional details - I have nodes that reference other nodes, using a Related Content field which is a paragraph of node references. So on the clone form, it's trying to load all those referenced entities nested inside each other, infinitely to the point of memory failure. The patch to not load an entity twice is great, but at some point I would like to be able to tell it that there's no need to recurse any further. If I'm clone a node with a reference to another node, it should only recurse that node IF I've selected to clone that entity - essentially building the form on demand instead of building the entire tree of checkboxes.
Posted a new issue here
Comment #25
cosmicdreams commented@nsciacca Oooo that's interesting.
Like we could build a tree structure with each leaf of the tree just being a combination of entity id and entity type (naturally unique identifiers). And then do cycle detection to see if we really need to keep extending the tree. Or maybe do some tree pruning after our already in place process of entity gathering completes.
Separate out the process of gathering all the entities that need to be cloned from the process of discovery?
Maybe we should break this out into a separate issue.
Comment #26
flocondetoileSure. It's a fatal error too. But the reason is different.
Comment #27
cosmicdreams commentedHere's the modified patch with using a local parameter instead of drupal_static.
Comment #28
dksdev01 commented#16 worked for me. will try #27 too...
Comment #29
joao sausen commented#27 worked nice for me too on last dev, I think we can move it to "Reviewed and Tested by the community"?
Comment #30
cosmicdreams commentedOK
Comment #32
vpeltot commentedCommited !
Thanks and sorry for the wait !
Comment #33
Anonymous (not verified) commentedI've just installed the latest beta, I still get this error.
Comment #34
cosmicdreams commented@samspinoy, it's technically still possible to get this error given a complex enough structure. But it helps relieve the excessive memory and processing time due to recursive / circular references.
Can you please create a new ticket and reference it here with your build's details and we can walk through it?
Comment #35
Anonymous (not verified) commentedSure: https://www.drupal.org/project/entity_clone/issues/3024435
Comment #37
sir_squall commentedI still go the error in the latest version of the module and in Drupal 9.5:
Fatal error: Allowed memory size of 671088640 bytes exhausted (tried to allocate 20480 bytes) in .../core/lib/Drupal/Core/Field/FieldItemBase.php on line 109