AssertionError: Cannot load the "paragraph" entity with NULL ID

Created on 12 May 2023, over 1 year ago

Problem/Motivation

When I try to replicate a simple node with paragraphs and using the paragraphs_asymmetric_translation_widgets module, I get this error:
AssertionError: Cannot load the "paragraph" entity with NULL ID. in assert() (line 295 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).

Proposed resolution

I noticed that this is because somehow, there are items inside onEntityReferenceRevisionsClone function that have null for $item['target_id']. See attached screenshot where I modified the code in paragraphs_asymmetric_translation_widgets/src/EventSubscriber/ReplicateAsymmetricParagraphsSubscriber.php to dump the item and skip to the next if $item['target_id'] is null. I propose checking if $item['target_id'] is null before trying to replicate it by adding:

          // Validate target_id before trying to replicate the ite.
          if (!isset($item['target_id']) || is_null($item['target_id'])) {
            continue;
          }

after line 75 in paragraphs_asymmetric_translation_widgets/src/EventSubscriber/ReplicateAsymmetricParagraphsSubscriber.php

Remaining tasks

- figure out exactly in which use cases $item['target_id'] is null
- create a patch

Full error:

The website encountered an unexpected error. Please try again later.
AssertionError: Cannot load the "paragraph" entity with NULL ID. in assert() (line 295 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).
assert(, 'Cannot load the "paragraph" entity with NULL ID.') (Line: 295)
Drupal\Core\Entity\EntityStorageBase->load(NULL) (Line: 122)
Drupal\replicate\Replicator->cloneByEntityId('paragraph', NULL) (Line: 80)
Drupal\paragraphs_asymmetric_translation_widgets\EventSubscriber\ReplicateAsymmetricParagraphsSubscriber->onEntityReferenceRevisionsClone(Object, 'replicate__entity_field__entity_reference_revisions', Object)
call_user_func(Array, Object, 'replicate__entity_field__entity_reference_revisions', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, Object) (Line: 224)
Drupal\replicate\Replicator->dispatchEventCloneEntityField(Object, 'field_col_uneqwidth2_item', Object) (Line: 208)
Drupal\replicate\Replicator->dispatchEventCloneEntityFields(Object) (Line: 143)
Drupal\replicate\Replicator->cloneEntity(Object) (Line: 123)
Drupal\replicate\Replicator->cloneByEntityId('paragraph', '1256') (Line: 80)
Drupal\paragraphs_asymmetric_translation_widgets\EventSubscriber\ReplicateAsymmetricParagraphsSubscriber->onEntityReferenceRevisionsClone(Object, 'replicate__entity_field__entity_reference_revisions', Object)
call_user_func(Array, Object, 'replicate__entity_field__entity_reference_revisions', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, Object) (Line: 224)
Drupal\replicate\Replicator->dispatchEventCloneEntityField(Object, 'field_page_body', Object) (Line: 208)
Drupal\replicate\Replicator->dispatchEventCloneEntityFields(Object) (Line: 143)
Drupal\replicate\Replicator->cloneEntity(Object) (Line: 97)
Drupal\replicate\Replicator->replicateEntity(Object) (Line: 113)
Drupal\replicate_ui\Form\ReplicateConfirmForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 595)
Drupal\Core\Form\FormBuilder->processForm('node_page_replicate_form', Array, Object) (Line: 323)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
🐛 Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

🇧🇪Belgium flyke

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024