Fatal error after saving the page not have a reuse entity

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Core\Entity\EntityStorageException</em>: The &quot;&quot; entity type does not exist. in <em class="placeholder">Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save()</em> (line <em class="placeholder">847</em> of <em class="placeholder">core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php</em>). <pre class="backtrace">Drupal\Core\Entity\EntityRepository-&gt;loadEntityByUuid(&#039;&#039;, &#039;&#039;) (Line: 31)
Drupal\entity_usage\Plugin\EntityUsage\Track\TextFieldEmbedBase-&gt;getTargetEntities(Object) (Line: 148)
Drupal\entity_usage\EntityUsageTrackBase-&gt;trackOnEntityCreation(Object) (Line: 171)
Drupal\entity_usage\EntityUsageTrackBase-&gt;trackOnEntityUpdate(Object) (Line: 107)
Drupal\entity_usage\EntityUpdateManager-&gt;trackUpdateOnEdition(Object) (Line: 41)
entity_usage_entity_update(Object)
call_user_func_array(&#039;entity_usage_entity_update&#039;, Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler-&gt;invokeAll(&#039;entity_update&#039;, Array) (Line: 206)
Drupal\Core\Entity\EntityStorageBase-&gt;invokeHook(&#039;update&#039;, Object) (Line: 835)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;invokeHook(&#039;update&#039;, Object) (Line: 535)
Drupal\Core\Entity\EntityStorageBase-&gt;doPostSave(Object, 1) (Line: 720)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;doPostSave(Object, 1) (Line: 460)
Drupal\Core\Entity\EntityStorageBase-&gt;save(Object) (Line: 838)
Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save(Object) (Line: 394)
Drupal\Core\Entity\EntityBase-&gt;save() (Line: 285)
Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem-&gt;preSave() (Line: 233)
Drupal\Core\Field\FieldItemList-&gt;delegateMethod(&#039;preSave&#039;) (Line: 191)
Drupal\Core\Field\FieldItemList-&gt;preSave() (Line: 873)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;invokeFieldMethod(&#039;preSave&#039;, Object) (Line: 823)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;invokeHook(&#039;presave&#039;, Object) (Line: 500)
Drupal\Core\Entity\EntityStorageBase-&gt;doPreSave(Object) (Line: 692)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;doPreSave(Object) (Line: 454)
Drupal\Core\Entity\EntityStorageBase-&gt;save(Object) (Line: 838)
Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save(Object) (Line: 394)
Drupal\Core\Entity\EntityBase-&gt;save() (Line: 285)
Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem-&gt;preSave() (Line: 233)
Drupal\Core\Field\FieldItemList-&gt;delegateMethod(&#039;preSave&#039;) (Line: 191)
Drupal\Core\Field\FieldItemList-&gt;preSave() (Line: 873)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;invokeFieldMethod(&#039;preSave&#039;, Object) (Line: 823)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;invokeHook(&#039;presave&#039;, Object) (Line: 500)
Drupal\Core\Entity\EntityStorageBase-&gt;doPreSave(Object) (Line: 692)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;doPreSave(Object) (Line: 454)
Drupal\Core\Entity\EntityStorageBase-&gt;save(Object) (Line: 838)
Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save(Object) (Line: 394)
Drupal\Core\Entity\EntityBase-&gt;save() (Line: 294)
Drupal\node\NodeForm-&gt;save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter-&gt;executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter-&gt;doSubmitForm(Array, Object) (Line: 590)
Drupal\Core\Form\FormBuilder-&gt;processForm(&#039;node_landing_page_edit_form&#039;, Array, Object) (Line: 319)
Drupal\Core\Form\FormBuilder-&gt;buildForm(Object, Object) (Line: 93)
Drupal\Core\Controller\FormController-&gt;getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
</pre>
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Firass Ziedan created an issue. See original summary.

firass.ziedan’s picture

Assigned: firass.ziedan » Unassigned
Status: Active » Needs review
StatusFileSize
new1.84 KB
firass.ziedan’s picture

firass.ziedan’s picture

marcoscano’s picture

Priority: Major » Normal
Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks for reporting this and for the patch.

Looking at the stack trace, it looks like there may be some broken markup that's causing the parser to break? Could you please provide more details about the setup you used to reproduce this issue? That would help us nail down exactly what made the system fail.

+++ b/src/Plugin/EntityUsage/Track/TextFieldEmbedBase.php
@@ -25,13 +25,18 @@ public function getTargetEntities(FieldItemInterface $item) {
-    foreach ($entities_in_text as $uuid => $entity_type) {
-      // Check if the target entity exists since text fields are not
-      // automatically updated when an entity is removed.
-      if ($target_entity = $this->entityRepository->loadEntityByUuid($entity_type, $uuid)) {
-        $valid_entities[] = $target_entity->getEntityTypeId() . "|" . $target_entity->id();
+    if (!empty($entities_in_text)) {
+      foreach ($entities_in_text as $uuid => $entity_type) {
+        // Check if the target entity exists since text fields are not
+        // automatically updated when an entity is removed.
+        if (!empty($uuid)) {
+          if ($target_entity = $this->entityRepository->loadEntityByUuid($entity_type, $uuid)) {
+            $valid_entities[] = $target_entity->getEntityTypeId() . "|" . $target_entity->id();
+          }
+        }

I agree the module shouldn't choke on bad content, but IMHO the fix should be in the plugins themselves, as part of the ::parseEntitiesFromText() method.

Also, it would be great to have a test that covers this scenario as well.

Thanks!

gngn’s picture

Status: Needs work » Needs review
StatusFileSize
new1.7 KB

I recently added entity_usage to a long running site and encountered a similiar error saving nodes:

Uncaught PHP Exception Drupal\\Core\\Entity\\EntityStorageException:
"The "" entity type does not exist."
at /core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php line 847,

I noticed empty data-entity-uuid and data-entity-type attributes.

I agree with @marcoscano in #5 that ::parseEntitiesFromText() is the best place to check for this.

I only encountered the error with Plugin\EntityUsage\Track\LinkIt and created a patch for that.
Plugin\EntityUsage\Track\EntityEmbed is very similar so I expanded the patch to that one.
I am not quite sure what to do with the other Track Plugins.

So the attached patch only handles Track\LinkIt and Track\EntityEmbed.

Oscaner’s picture

StatusFileSize
new958 bytes

We cannot handle all Track plugin, because they are unknown, how much, how do.
So i think should focus on base code to fix it.

Status: Needs review » Needs work

The last submitted patch, 7: 3098733-7.patch, failed testing. View results

richardbporter made their first commit to this issue’s fork.

richardbporter’s picture

Patch in #6 works. I'm not sure the HtmlLink plugin needs this change because its getting the entity type and ID from the route, if it is routed. I added some logic to MediaEmbed combined with the patch in #6 to a new MR. I can attempt to write tests if this approach is ok.

richardbporter’s picture

Status: Needs work » Needs review
richardbporter’s picture

StatusFileSize
new5.55 KB
new4.97 KB

Uploaded patch and interdiff from #6.

drupal-son’s picture

I have the same error and can confirm patch #6 is working.
In my case, there is something adding markup like this with empty attributes making the parser break up after saving.

<a class="" data-entity-substitution="" data-entity-type="" data-entity-uuid="" href="https://something.com" id="" rel="" target="_blank" title="">

If removing the empty attributes, the node gets saved.
When using the patch and keeping the original empty attributes it worked too!

john cook’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm that patch #13 fixes the issue; at least with the LinkIt plugin.

Changing to RTBC.

richardbporter’s picture

The test failures after rebasing seem to be unrelated and are currently happening in 8.x-2.x-dev: https://www.drupal.org/pift-ci-job/2354527

baluertl’s picture

Title: fatal error after saveing the page not have a reuse entity » Fatal error after saving the page not have a reuse entity
dasginganinja’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new6.46 KB
new815 bytes

I also ran into this issue today and tried patch #13.

It stumbled upon the CKEditor image plugin so I added support for that in.

I'm not sure if this needs additional tests, but it's not RTBC anymore :)

marcoscano’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Looks good to me, thanks everyone who contributed!
Committed and tagged a new release with the fix in.

Status: Fixed » Closed (fixed)

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