Problem/Motivation
A site might have orphaned paragraphs that were assigned to now-deleted fields on the referenced parent entity. The code does not properly check if the paragraph's parent field still exists
Steps to reproduce
Proposed resolution
62: $parentField = $entity->get('parent_field_name')->getString();
63: $index = $this->getMultiValueIndex($parentEntity->$parentField->getValue(), $pid);
maybe we need a check like below?
$parentEntity->hasField($parentField)
Remaining tasks
User interface changes
API changes
Data model changes
Original report
I'm trying to replace content, and the configuration includes fields from paragraphs too
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /en/batch?id=34176&op=do_nojs&op=do
StatusText: error
ResponseText: The website encountered an unexpected error. Try again later.Error: Call to a member function getValue() on null in Drupal\scanner\Plugin\Scanner\Paragraph->handleParentRelationship() (line 63 of modules/contrib/scanner/src/Plugin/Scanner/Paragraph.php). Drupal\scanner\Plugin\Scanner\Entity->replace() (Line: 135)
Drupal\scanner\Form\ScannerConfirmForm::batchReplace() (Line: 297)
_batch_process() (Line: 139)
_batch_do() (Line: 95)
_batch_page() (Line: 52)
Drupal\system\Controller\BatchController->batchPage()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 637)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 124)
Drupal\cloudflare\CloudFlareMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)
Comments
Comment #2
damienmckennaDo you see any errors when you do a search?
Comment #3
damienmckennaWe definitely need to get this fixed before 2.0.0 is released.
Comment #4
dimitriskr commentedIs the suggested solution ok? I didn't have this error on beta1, should I investigate my content structure when that happens or just go with it?
Comment #6
dimitriskr commentedNo, there was nothing there
Comment #7
damienmckennaThe code was heavily rewritten between beta1 and beta2, so it's likely a bug slipped in.
Looking at the MR:
You need to add a line break before the $index= line.
Also, if $parentEntity doesn't have $parentField then how could it be a parent entity? Might that be a problem in the data? Are you able to edit that node and save it without any problems?
Comment #8
dimitriskr commentedMy speculation is that the paragraph was created when that field existed in the parent node but since the field got deleted and the paragraph stayed there.
The code does not correctly identify orphaned paragraphs. I ran
drush err:purge paragraphto clean them up and it seems it works nowMaybe using this service
\Drupal::service('entity_reference_revisions.orphan_purger')->isUsed($entity)is better, near the edited lines?Comment #9
dimitriskr commentedComment #10
dimitriskr commentedI also got this error
and
\Drupal::service('entity_reference_revisions.orphan_purger')->isUsed($entity)reports both Entity and parent entity not being usedSo locally I did this
Comment #13
damienmckennaWith all the rewriting this week in how the replace operation works, I created a MR where it only processes nested entities where the root entity can be loaded, hopefully this will cover the problem. If needed we can expand it further, but let me know if this works for you.