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

  1. Create new paragraph type "ptest" with a simple text field
  2. Enable panelizer settings for paragraph "ptest"
  3. Node type "ntest" with paragraphs field holding paragraph "ptest"
  4. Create node of type ntest with a singel paragraph added
  5. Edit the node and add a new paragraph
  6. 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

Comments

derhasi’s picture

Title: PDO Exception when updating paragraph field due top panelizer » PDO Exception when updating paragraph field due to panelizer
Priority: Normal » Major
derhasi’s picture

derhasi’s picture

Status: Active » Needs review
StatusFileSize
new22.55 KB

Adding test for this problem with attached patch. This should fail with a PDO Exception.

Status: Needs review » Needs work

The last submitted patch, 3: pdo_exception_when-2432629-3.patch, failed testing.

derhasi’s picture

StatusFileSize
new22.69 KB

Updated test with additional module enables.

derhasi’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: pdo_exception_when-2432629-5.patch, failed testing.

derhasi’s picture

Status: Needs work » Needs review
StatusFileSize
new22.84 KB

I'm sorry testbot, but I do not get why you are not finding the features module.

Status: Needs review » Needs work

The last submitted patch, 8: pdo_exception_when-2432629-7.patch, failed testing.

derhasi’s picture

Status: Needs work » Needs review
StatusFileSize
new22.55 KB

https://www.drupal.org/project/testbot says

Dependencies only get built when the new dev release is rolled, every 12 hours. So if you change dependencies, it won't be reflected until the new dev tarball is rolled.

.

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.

derhasi’s picture

StatusFileSize
new657 bytes

To make it easier, there is a patch to simply update the test_dependencies[]

  • jeroen.b committed 5421920 on 7.x-1.x authored by derhasi
    Issue #2432629 by derhasi: PDO Exception when updating paragraph field...
jeroen.b’s picture

Pushed your latest patch

The last submitted patch, 3: pdo_exception_when-2432629-3.patch, failed testing.

derhasi’s picture

StatusFileSize
new24.08 KB

If the dependencies are resolved, this test should run and fail with a PDOExeption. If not, maybe test_dependencies[] is not working.

Status: Needs review » Needs work

The last submitted patch, 16: pdo_exception_when-2432629-16.patch, failed testing.

derhasi’s picture

@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.

  • jeroen.b committed 7c74d76 on 7.x-1.x authored by derhasi
    Issue #2432629 by derhasi: PDO Exception when updating paragraph field...
derhasi’s picture

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

The 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.

jeroen.b’s picture

derhasi’s picture

The 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 .

jeroen.b’s picture

Tried that now, new test: https://qa.drupal.org/pifr/test/668608

derhasi’s picture

As long as the testbot issue is not resolved. Can anyone test that manually, so we can get that bugfix in the dev release? ;)

  • jeroen.b committed 0274f30 on 7.x-1.x authored by derhasi
    Issue #2432629 by derhasi: PDO Exception when updating paragraph field...
jeroen.b’s picture

Status: Needs review » Postponed

Tested it myself and committed to dev, thanks!
I'll keep this issue open until the issue with the test is fixed.

Status: Postponed » Needs work

The last submitted patch, 20: pdo_exception_when-2432629-20.patch, failed testing.

jeroen.b’s picture

Status: Needs work » Postponed
derhasi’s picture

Status: Postponed » Needs review
StatusFileSize
new1.09 KB

As 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.

Status: Needs review » Needs work

The last submitted patch, 29: pdo_exception_when-revert-2432629-29.patch, failed testing.

derhasi’s picture

Status: Needs work » Fixed

Great. 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.

jeroen.b’s picture

Great!

Status: Fixed » Closed (fixed)

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