Integrity constraint violation: 1048 Column 'langcode' cannot be null

Created on 10 August 2017, over 7 years ago
Updated 20 July 2023, over 1 year ago

Problem/Motivation

I receive a `SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'langcode' cannot be null: INSERT INTO {paragraphs_item}` when saving a paragraph item attached through certain conditions like Layout Builder (see #2901390-15: Integrity constraint violation: 1048 Column 'langcode' cannot be null β†’ ).

Steps to reproduce

I get an error when trying to save. The set up is this is a paragraph entity on a media entity being created through entity browser entity form. It seems that the paragraph isn't receiving a langcode from massageFormValues in the InlineParagraphsWidget.

Here is the complete backtrace:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'langcode' cannot be null: INSERT INTO {paragraphs_item} (revision_id, type, uuid, langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => pull_quote_with_image [:db_insert_placeholder_2] => 0da9476f-29a9-42b4-9c8d-2de3bba2fd13 [:db_insert_placeholder_3] => ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 777 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Drupal\Core\Database\Statement->execute(Array, Array) (Line: 624)
Drupal\Core\Database\Connection->query('INSERT INTO {paragraphs_item} (revision_id, type, uuid, langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3)', Array, Array) (Line: 87)
Drupal\Core\Database\Driver\mysql\Connection->query('INSERT INTO {paragraphs_item} (revision_id, type, uuid, langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3)', Array, Array) (Line: 32)
Drupal\Core\Database\Driver\mysql\Insert->execute() (Line: 850)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->doSaveFieldItems(Object) (Line: 263)
Drupal\Core\Entity\ContentEntityStorageBase->doSave(NULL, Object) (Line: 392)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 768)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 364)
Drupal\Core\Entity\Entity->save() (Line: 259)
Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem->preSave() (Line: 254)
Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem->preSave() (Line: 244)
Drupal\Core\Field\FieldItemList->delegateMethod('preSave') (Line: 202)
Drupal\Core\Field\FieldItemList->preSave() (Line: 479)
Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldMethod('preSave', Object) (Line: 429)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('presave', Object) (Line: 435)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 298)
Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object) (Line: 389)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 768)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 364)
Drupal\Core\Entity\Entity->save() (Line: 140)
Drupal\entity_browser_entity_form\Plugin\EntityBrowser\Widget\EntityForm->Drupal\entity_browser_entity_form\Plugin\EntityBrowser\Widget\{closure}(Object, 0)
array_walk(Array, Object) (Line: 141)
Drupal\entity_browser_entity_form\Plugin\EntityBrowser\Widget\EntityForm->submit(Array, Array, Object) (Line: 189)
Drupal\entity_browser\Form\EntityBrowserForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('entity_browser_wysiwyg_embed_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('entity_browser_wysiwyg_embed_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
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}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I see the same error mentioned on this issue β†’ .

Could others try this patch too? @TrevorBradley?

Proposed resolution

Patch the paragraph blob to include `langcode`.

Remaining tasks

  • Test the patch in #2901390-82: Integrity constraint violation: 1048 Column 'langcode' cannot be null β†’ :
    • If you added a block before applying the patch, then trying to save the layout with that added block, it will not work, because the Layout Builder's intermediate blob state is not being addressed here. What is being addressed here is the process of adding the block via the form. To test if the patch works for you, you need to test with a completely new layout (not with an already existing intermediate state of the layout). IMO it does not make sense trying to fix the intermediate state of blobs. What gets into the blob, stays in the blob.
    • If you still encounter the error - then once more like I already said in #79 please - at least provide a deterministic way to reproduce the error like #80 or even better write an additional Unit / Kernel or functional test. Having an automated test would help us to reduce misunderstandings, we can directly address the problem and proceed with this issue.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

@todo

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States oknate Greater New York City Area

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • This patch is modified according to #10. Although part of the code in this issue has been merged, the problem still exists. When I apply paragraphs in a block, this block is applied in layout build. When saving the layout, this error will be prompted.
    drupal version is 10.1

Production build 0.71.5 2024