When trying to add a section containing an inline block to the library, a 500 error occurs:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /section_library/add/section/overrides/node.21/0?_wrapper_format=drupal_dialog.off_canvas&ajax_form=1
StatusText: Internal Server Error
ResponseText: The website encountered an unexpected error. Please try again later.Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin-en' for key 'user__name': INSERT INTO {users_field_data} ("uid", "langcode", "preferred_langcode", "preferred_admin_langcode", "name", "pass", "mail", "timezone", "status", "created", "changed", "access", "login", "init", "default_langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14); Array
(
[:db_insert_placeholder_0] => 9
[:db_insert_placeholder_1] => en
[:db_insert_placeholder_2] => en
[:db_insert_placeholder_3] => 
[:db_insert_placeholder_4] => admin
[:db_insert_placeholder_5] => $S$E7N9uvyKaZBP8jpy1Jfy3usstbyhTfpyPrkq50eSYTNrbSoLCtwh
[:db_insert_placeholder_6] => sites@example.com
[:db_insert_placeholder_7] => Europe/Brussels
[:db_insert_placeholder_8] => 1
[:db_insert_placeholder_9] => 1611759379
[:db_insert_placeholder_10] => 1611759488
[:db_insert_placeholder_11] => 1611842998
[:db_insert_placeholder_12] => 1611759692
[:db_insert_placeholder_13] => sites@example.com
[:db_insert_placeholder_14] => 1
)
in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 810 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php). Drupal\Core\Database\StatementWrapper->execute(Array, Array) (Line: 826)
Drupal\Core\Database\Connection->query('INSERT INTO {users_field_data} ("uid", "langcode", "preferred_langcode", "preferred_admin_langcode", "name", "pass", "mail", "timezone", "status", "created", "changed", "access", "login", "init", "default_langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14)', Array, Array) (Line: 97)
Drupal\Core\Database\Driver\mysql\Connection->query('INSERT INTO {users_field_data} ("uid", "langcode", "preferred_langcode", "preferred_admin_langcode", "name", "pass", "mail", "timezone", "status", "created", "changed", "access", "login", "init", "default_langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14)', Array, Array) (Line: 32)
Drupal\Core\Database\Driver\mysql\Insert->execute() (Line: 1011)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->saveToSharedTables(Object) (Line: 949)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->doSaveFieldItems(Object, Array) (Line: 27)
Drupal\user\UserStorage->doSaveFieldItems(Object) (Line: 622)
Drupal\Core\Entity\ContentEntityStorageBase->doSave(NULL, Object) (Line: 452)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 801)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 130)
Drupal\section_library\Form\AddSectionToLibraryForm->cloneReferencedEntities(Object) (Line: 92)
Drupal\section_library\Form\AddSectionToLibraryForm->cloneAndReplaceSectionComponents(Object) (Line: 63)
Drupal\section_library\Form\AddSectionToLibraryForm->deepCloneSection(Object) (Line: 149)
Drupal\section_library\Form\AddSectionToLibraryForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 113)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('section_library_add_section_to_library', Array, Object) (Line: 321)
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: 573)
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: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
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: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 706)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I was confused because there was no reference field to a user on the block. So did some debugging, and the culprit is the content_translation_uid field. Although the same error would occur if the site builder adds a normal user entity reference field to a block.

My suggestion is to exclude cloning user objects during the deep clone. Either keep the original entity reference, or empty the field. Probably best to keep the original reference.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Grayle created an issue. See original summary.

Grayle’s picture

Status: Active » Needs review
FileSize
791 bytes

Quick patch that doesn't clone user entities but keeps the same reference.

jhedstrom’s picture

FileSize
1.3 KB
1.23 KB

We also saw this deep cloning things like media and taxonomy terms, which is undesirable as it would duplicate images, terms, etc instead of pointing at the original reference.

I'm not quite sure exactly what should be deep cloned here? Paragraphs perhaps?

Grayle’s picture

I think paragraphs and other content blocks?

mahmoud-zayed’s picture

Status: Needs review » Fixed

Thanks @Grayle & @jhedstrom, Yes so far the allowed types are block_content and paragraph, I reversed it, so use getAllowedTypes instead of ignoredTypes

mahmoud-zayed’s picture

Status: Fixed » Closed (fixed)

Added to 1.0.0-beta2 release!