Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
With the new panelizer integration, we get a fatal PDOException when updating an existing (panelizer enabled) entity with an existing paragraph item ad adding a new paragraph item to it.
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'paragraphs_item-10-10-default' for key 'PRIMARY': INSERT INTO {panelizer_entity} (entity_type, entity_id, revision_id, name, no_blocks, css_id, css, pipeline, contexts, relationships, did, view_mode, css_class, title_element, link_to_entity, extra) 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, :db_insert_placeholder_15); Array ( [:db_insert_placeholder_0] => paragraphs_item [:db_insert_placeholder_1] => 10 [:db_insert_placeholder_2] => 10 [:db_insert_placeholder_3] => paragraphs_item:ttttt:default:default [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => standard [:db_insert_placeholder_8] => a:0:{} [:db_insert_placeholder_9] => a:0:{} [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => default [:db_insert_placeholder_12] => [:db_insert_placeholder_13] => H2 [:db_insert_placeholder_14] => 1 [:db_insert_placeholder_15] => a:0:{} ) in drupal_write_record() (line 7239 of [...]/docroot/includes/common.inc).
Steps to reproduce
- Create new paragraph type "ptest" with a simple text field
- Enable panelizer settings for paragraph "ptest"
- Node type "ntest" with paragraphs field holding paragraph "ptest"
- Create node of type ntest with a singel paragraph added
- Edit the node and add a new paragraph
- PDO Exception occurs
Proposed resolution
The problem comes from PanelizerEntityParagraphsItem->get_default_panelizer_object() as it returns a cached object. So that is passed by reference to the second delta of the field and therefore overrides entity id and revision id of the first delta. I've already a patch for that by using clone, but want to add a test first. Will do that in the next comment
Remaining tasks
- Write test
- Upload patch
Comment | File | Size | Author |
---|---|---|---|
#29 | pdo_exception_when-revert-2432629-29.patch | 1.09 KB | derhasi |
#20 | pdo_exception_when-2432629-20.patch | 1.09 KB | derhasi |
#16 | pdo_exception_when-2432629-16.patch | 24.08 KB | derhasi |
Comments
Comment #1
derhasi CreditAttribution: derhasi commentedComment #2
derhasi CreditAttribution: derhasi commentedComment #3
derhasi CreditAttribution: derhasi commentedAdding test for this problem with attached patch. This should fail with a PDO Exception.
Comment #5
derhasi CreditAttribution: derhasi commentedUpdated test with additional module enables.
Comment #6
derhasi CreditAttribution: derhasi commentedComment #8
derhasi CreditAttribution: derhasi commentedI'm sorry testbot, but I do not get why you are not finding the features module.
Comment #10
derhasi CreditAttribution: derhasi commentedhttps://www.drupal.org/project/testbot says
.
Due to that, we would need to add the test to our dev release, before it can take effect.
@jeroen.b can you add that latest test, so we can make it work here :) Currently there is no fix, so it will break at the moment. I will post the fix, once the test is running smoothely.
I marked the patch to be not tested, so we spare running the testbot again.
Comment #11
derhasi CreditAttribution: derhasi commentedTo make it easier, there is a patch to simply update the test_dependencies[]
Comment #13
jeroen.b CreditAttribution: jeroen.b commentedPushed your latest patch
Comment #16
derhasi CreditAttribution: derhasi commentedIf the dependencies are resolved, this test should run and fail with a PDOExeption. If not, maybe test_dependencies[] is not working.
Comment #18
derhasi CreditAttribution: derhasi commented@jeroen.b , we still got the testbot dependency issue. So I guess we need to provide the dependencies as real "dependencies" instead of "test_dependencies". Can you apply this patch to the dev release, so testbot recognizes the dependencies (they are all located in the panels_test.info). After that I hope we get the testbot running.
Comment #20
derhasi CreditAttribution: derhasi commentedThe testbot still does not fetch the dependencies. So it currently fails. Maybe this patch triggers a new build. Otherwise I would need to reach out to the testbot team :)
So, here is the fix for this issue. By simply cloning the default panelizer object, we do not need to worry about updates by reference.
Comment #21
jeroen.b CreditAttribution: jeroen.b commentedNew test: https://qa.drupal.org/pifr/test/668608
Comment #22
derhasi CreditAttribution: derhasi commentedThe dependencies still are not resolved. Did you try to disable testbot and enable it again? Currently I can't think of any other workaround till we get an answer in https://www.drupal.org/node/2441985 .
Comment #23
jeroen.b CreditAttribution: jeroen.b commentedTried that now, new test: https://qa.drupal.org/pifr/test/668608
Comment #24
derhasi CreditAttribution: derhasi commentedAs long as the testbot issue is not resolved. Can anyone test that manually, so we can get that bugfix in the dev release? ;)
Comment #26
jeroen.b CreditAttribution: jeroen.b commentedTested it myself and committed to dev, thanks!
I'll keep this issue open until the issue with the test is fixed.
Comment #28
jeroen.b CreditAttribution: jeroen.b commentedComment #29
derhasi CreditAttribution: derhasi commentedAs the testbot now seems to be running with the latest dependencies, I will do a last test here, to verify the test originally broke, by reverting the patch with the attached patch.
Comment #31
derhasi CreditAttribution: derhasi commentedGreat. This is the way the test should have failed in the first place. So we verified that. And now, as the dev branch does not fail this issue is fixed.
To clarify: the last attached patch reverts the fix of this issue, so we can make sure the test originally failed as it was expected.
So I am marking this as beeing fixed.
Comment #32
jeroen.b CreditAttribution: jeroen.b commentedGreat!