Latest update

EntityReferenceEntityFormatter.php uses $recursive_render_id key for incrementing to detect recursion, but the key only uses the end of the node reference chain. This leads to false positives on batch processes that edit nodes whose reference chains end the same.

Recursive_render_id key is in the form of "node-[content-type]-field_[reference-field-name]-[nid-of-node-that-references]-node-[last-node's-nid-that-is-referenced]". For example "node-unit-field_unit_ref-60404378-node-60404377"

However if I have a chain of nodes and I batch process the a[n] nodes (below)..

  1. a1->b->c->d
  2. a2->b->c->d
  3. ...
  4. a21->b->c->d

.., then the recursion detection increments the end of reference chains: "c->d" and calls a false positive, when it reaches above 20 items.

As there is no recursion in any one node chain (while batch editing the a[n] nodes), this is a false positive. EntityReferenceEntityFormatter's $recursive_render_id should use the whole reference chain as an increment key so it doesn't detect false positives on batch processes.

Feel free not to read the rest of the description, as I wrote it in the first stages of debugging:

Update

It seems to me that when you have a "deep rabbit hole" of references and batch process them (even without Feeds - with VBO), then recursion detection thinks it is one render and prints an error.

However no real recursion anywhere - every reference chain of nodes is unique and no node occurs more than once in any chain.

I made a couple of tests and found that the problem also occurs with VBO batch process (as well as feeds) when batch processing contact nodes with this kind of reference structure:

contact -> unit_x -> unit_y -> unit_z (all chains end with unit_z)

When batch processing contacts, I get recursion errors on unit content:

Recursive rendering detected when rendering entity node: [last unit in chain: unit_z], using the .. field on the [previous unit in chain] entity. Aborting rendering.

However no problems when batch processing all of the units at once - error only occurs when batch processing contact nodes.

-- end of update --

Problem/Motivation

When updating about 480 nodes with Feeds, which use entity reference fields that all point to one certain node, then EntityReferenceEntityFormatter.php recursion protection gets tripped.

If I change the following constant in EntityReferenceEntityFormatter.php..
const RECURSIVE_RENDER_LIMIT = 20;
.. to this..
const RECURSIVE_RENDER_LIMIT = 500;
.. then everything works and nodes get updated.

Steps to reproduce

  1. Create node that has entity reference field
  2. Import a couple of hundred items with Feeds, all of which reference one certain node
  3. After import Drupal log is filled with recursion error messages that come from EntityReferenceEntityFormatter.php

Proposed resolution

Change EntityReferenceEntityFormatter.php recursion protection so it works with Feeds.

Comments

hannes.himma created an issue. See original summary.

cilefen’s picture

hanneshh’s picture

The same recursion protection creates the error, but it seems to me that the difference is the recursion protection sees Feeds batch processing as if the batch process was one node in a recursion over 20 times. However there is no recursion in any one node that feeds is processing.

I have nodes a1, a2, a3, a4, .. and all of them reference node b only once (and each node is showing it only once). When Feeds batch processes these nodes (updates them), then it "thinks" there is a recursion. But actually its:

  • a1 -> b
  • a2 -> b
  • ..
  • a20 -> b

.. and after that - recursion error. However no recursion in any one node :)

I've also tried the patch in the bug report #2940605 and it didn't make any difference.

cilefen’s picture

Could this be more of an issue for the Feeds maintainers to solve?

cilefen’s picture

hanneshh’s picture

As far as I understand #3151977 addresses rendering the same media item in one node over 20 times. However in my case i'm referencing one certain node only once in all of the nodes. - I have over 20 nodes that each reference the same node only once and also show the referenced node only once.

The problem only occurs when batch processing these nodes with Feeds - not when viewing one node at a time or even indexing for search. It doesn't even occur, when I create a Views view that shows all of these nodes at once.

It looks as if batch processing these nodes EntityReferenceEntityFormatter.php treats batch process as if it was one render and keeps adding to static::$recursiveRenderDepth[$recursive_render_id] even though no recursion in any one node.

hanneshh’s picture

It seems to me that when you have a "deep rabbit hole" of references and batch process them (even without Feeds - with VBO), then recursion detection thinks it is one render and prints an error.

However no real recursion anywhere - every reference chain of nodes is unique and no node occurs more than once in any chain.

I made a couple of tests and found that the problem also occurs with VBO batch process (as well as feeds) when batch processing contact nodes with this kind of reference structure:

contact -> unit_x -> unit_y -> unit_z (all chains end with unit_z)

When batch processing contacts, I get recursion errors on unit content:

Recursive rendering detected when rendering entity node: [last unit in chain: unit_z], using the .. field on the [previous unit in chain] entity. Aborting rendering.

However no problems when batch processing all of the units at once - error only occurs when batch processing contact nodes.

hanneshh’s picture

Issue summary: View changes
hanneshh’s picture

Title: Feeds incorrectly trips EntityReferenceEntityFormatter.php recursion protection » EntityReferenceEntityFormatter's $recursive_render_id only looks at one parent which causes false positives on batch processes
Issue summary: View changes
hanneshh’s picture

hanneshh’s picture

Issue summary: View changes
hanneshh’s picture

Issue summary: View changes
hanneshh’s picture

Issue summary: View changes
hanneshh’s picture

Issue summary: View changes
hanneshh’s picture

Issue summary: View changes
hanneshh’s picture

Issue summary: View changes
larowlan’s picture

Issue tags: -Entity Reference, -recursion

Can we get smarter about how we track the recursion? Perhaps tracking the path (which in this case are unique) rather than the individual items

hanneshh’s picture

Since it is a recursion detector, wouldn't the easiest way to fix it be to change:
const RECURSIVE_RENDER_LIMIT = 20;
.. to
const RECURSIVE_RENDER_LIMIT = 999;
.. or some other exceptionally large number?

Or make the limit configurable?

Otherwise it looks like one would have to change a lot of code.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Status: Active » Closed (duplicate)

#2940605: Can only intentionally re-render an entity with references 20 times is solved so closing this as a duplicate - proper recursion detection is now implemented.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.