I tried to export a node with paragraphs and an entity reference to a media entity in the paragraphs. There i got the following error:

PHP Fatal error:  Nesting level too deep - recursive dependency? in /Users/christianfritsch/repositories/thunder/thunder/profiles/thunder/modules/default_content/src/DefaultContentManager.php on line 345
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/drush:0
PHP   2. require() /usr/local/bin/drush:10
PHP   3. drush_startup() phar:///usr/local/bin/drush/drush:114
PHP   4. drush_main() phar:///usr/local/bin/drush/includes/startup.inc:325
PHP   5. Drush\Boot\BaseBoot->bootstrap_and_dispatch() phar:///usr/local/bin/drush/includes/preflight.inc:66
PHP   6. drush_dispatch() phar:///usr/local/bin/drush/lib/Drush/Boot/BaseBoot.php:67
PHP   7. call_user_func_array:{phar:///usr/local/bin/drush/includes/command.inc:185}() phar:///usr/local/bin/drush/includes/command.inc:185
PHP   8. drush_command() phar:///usr/local/bin/drush/includes/command.inc:185
PHP   9. _drush_invoke_hooks() phar:///usr/local/bin/drush/includes/command.inc:217
PHP  10. call_user_func_array:{phar:///usr/local/bin/drush/includes/command.inc:366}() phar:///usr/local/bin/drush/includes/command.inc:366
PHP  11. drush_default_content_export_references() phar:///usr/local/bin/drush/includes/command.inc:366
PHP  12. Drupal\default_content\DefaultContentManager->exportContentWithReferences() /Users/christianfritsch/repositories/thunder/thunder/profiles/thunder/modules/default_content/drush/default_content.drush.inc:85
PHP  13. Drupal\default_content\DefaultContentManager->getEntityReferencesRecursive() /Users/christianfritsch/repositories/thunder/thunder/profiles/thunder/modules/default_content/src/DefaultContentManager.php:266
PHP  14. array_unique() /Users/christianfritsch/repositories/thunder/thunder/profiles/thunder/modules/default_content/src/DefaultContentManager.php:345

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chr.fritsch created an issue. See original summary.

jwilson3’s picture

I can confirm this error happens when trying to export paragraphs to code.

* Paragraphs-8.x-1.0-rc5
* Default_content-8.x-1.x-dev

The problem is definitely coming from this line in class DefaultContentManager::getEntityReferencesRecursive()

    return array_unique($entity_dependencies, SORT_REGULAR);
sqndr’s picture

I just stumbled upon the same issue, when exporting a node (drush dce node 1 --folder=node) that contains multiple paragraph fields.

pguillard’s picture

Status: Active » Needs review
FileSize
424 bytes

I had the same problem, and found out the same solution.

andypost’s picture

Status: Needs review » Needs work

This is wrong fix
Actual problem here that ContentEntityBase::referencedEntities() does not returns keyed array as the module supposes

andypost’s picture

Status: Needs work » Needs review
FileSize
4.57 KB

Patch fixes the recursion by indexing entities by type:ID

Also it changes protected method in BC way

PS: formattable changes could be separate but check for interface should be there to prevent php errors about passing other then ContentEntityInterface

Status: Needs review » Needs work

The last submitted patch, 6: 2724281-6.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
FileSize
749 bytes
4.57 KB

Proper condition

Status: Needs review » Needs work

The last submitted patch, 8: 2724281-7.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review

Something weird with bot and last patch is wrong

andypost’s picture

andypost’s picture

Closed as duplicate also passing array by reference keeps memory usage low

Status: Needs review » Needs work

The last submitted patch, 12: 2724281-12.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
andypost’s picture

larowlan’s picture

+++ b/src/DefaultContentManager.php
@@ -319,30 +319,51 @@ class DefaultContentManager implements DefaultContentManagerInterface {
+    return $entity->getEntityTypeId() . ':' . $entity->id();

Any reason we can't use $entity->uuid() here instead?

Other than that, looks RTBC to me.

gaydabura’s picture

Status: Needs review » Reviewed & tested by the community

@andypost, much better then detect max level.
@larowlan actually this hash is temporary and uuid is in returned array as key.
http://cgit.drupalcode.org/default_content/tree/src/DefaultContentManage...
RTBC to me aswell

andypost’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

I think we need tests for nesting
Also uuid vs hash is a good question, the main idea is to keep that key easy to debug

OTOH as @Alexey pointed we already use uuid to index

andypost’s picture

andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
4.6 KB
1.93 KB
6.58 KB

Removed key gen method and using uuid
Here's a test, before patch only 2 entities are exported

The last submitted patch, 20: 2724281-recursion-test-only.patch, failed testing.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

Will leave at RTBC till Monday then commit

  • larowlan committed 10c07ee on 8.x-1.x authored by andypost
    Issue #2724281 by andypost, pguillard, larowlan, chr.fritsch, jwilson3,...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Fixed - thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.