When saving an existent node the following error occurs:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-31-31-square' 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] => node [:db_insert_placeholder_1] => 31 [:db_insert_placeholder_2] => 31 [:db_insert_placeholder_3] => node:pathway:default:half [: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] => square [: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 7136 of /includes/common.inc).

I have been able to solve the problem, but not the reasoning behind the problem. The problems occurs when hook_entity_update() method on PanelizerEntityDefault does not return the result of calling drupal_write_record() when $panelizer->display_is_modified is empty. The only place I've found hook_entity_update() method to be called is panelizer_entity_update() which doesn't expects a return value from it. Secondly, this error doesn't occur in all node content-types, and I've not been able understand why it occurs in some content-types but not in others.

The attached patch solves the issue by adding a return to PanelizerEntityDefault->hook_entity_update() with the result of drupal_write_record() when $panelizer->display_is_modified is empty.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

devuo’s picture

merlinofchaos’s picture

You'll need to do some more checking as to why this works, since that method is not expected to have a return value. Perhaps you need to do some backtraces to see if there is something else going on?

devuo’s picture

public function hook_entity_update($entity) {

      …

      if ($this->supports_revisions) {
        if (empty($panelizer->revision_id) || $panelizer->revision_id != $revision_id) {
          $panelizer->revision_id = $revision_id;
          $update = array();
        }
        else {
          $update = array('entity_type', 'revision_id', 'view_mode');
        }
      }

      …

      drupal_write_record('panelizer_entity', $panelizer, $update);

The problem apparently arises from setting $update to an empty array. By setting $update as an empty array, drupal_write_record() will use db_insert() instead of db_update(). The following also fixes the problem:

public function hook_entity_update($entity) {

      …

      if ($this->supports_revisions) {
        if (empty($panelizer->revision_id) || $panelizer->revision_id != $revision_id) {
          $panelizer->revision_id = $revision_id;
        }

        $update = array('entity_type', 'revision_id', 'view_mode');
      }

      …

      drupal_write_record('panelizer_entity', $panelizer, $update);

Given that the nodes exist, this leads me to think the problem is not in hook_entity_update() method but in insert or somewhere else where $panelizer->revision_id is first set.

merlinofchaos’s picture

Well, that code is meant to be used when it thinks it has to add a new record. It thinks it has to add a new record when the requested revision id doesn't match the loaded revision id, which is normally the case.

So that leads to...why does the requested revision id not match the loaded revision id, yet there is a record for that revision id in the database?

devuo’s picture

Another tidbit: I have three display modes panelized for this node content-type, two of them have a revision id, the other one, doesn't. This always occurs for when editing any node of this content-type.

merlinofchaos’s picture

Interesting. What is the difference in Panelizer configuration between those view modes? That is likely going to be the culprit, somehow.

DamienMcKenna’s picture

DamienMcKenna’s picture

stockliasteroid’s picture

I can confirm that this happens if not all of the display modes on a panelized node are set to be panelized. In my case, the Default display mode was set to be panelized and had a default panel provided, but Full Page Override and Teaser were not. When I switched those modes to be panelized as well, the issue went away.

Also of note, the issue arised when saving nodes en masse using editableviews. I hadn't run into it when using the standard node editing UI. However, it's possible that this issue was localized to a specific node that we hadn't edited yet, the nodes themselves came in as part of a migration so haven't all been touched via the UI yet.

olak’s picture

i also have this bug, in openatrium. the error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-235-522-page_manager' 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#012(#012    [:db_insert_placeholder_0] => node#012    [:db_insert_placeholder_1] => 235#012    [:db_insert_placeholder_2] => 522#012    [:db_insert_placeholder_3] => node:diavouleusi_intro:default#012    [:db_insert_placeholder_4] => 0#012    [:db_insert_placeholder_5] => #012    [:db_insert_placeholder_6] => #012    [:db_insert_placeholder_7] => standard#012    [:db_insert_placeholder_8] => a:0:{}#012    [:db_insert_placeholder_9] => a:0:{}#012    [:db_insert_placeholder_10] => 0#012    [:db_insert_placeholder_11] => page_manager#012    [:db_insert_placeholder_12] => #012    [:db_insert_placeholder_13] => H2#012    [:db_insert_placeholder_14] => 1#012    [:db_insert_placeholder_15] => a:0:{}#012)#012 in drupal_write_record() (line 7199 of /var/aegir/platforms/openatrium-7.x-2.12/includes/common.inc).

for me comes in custom content types. especially in one, with a date field (with 2 values, starting and ending) when i change both values to past dates.
the spooky thing is that the node becomes somehow corrupt. from inside drupal, you cant access it, not even from the admin/content.
i tried both the patch and to turn panelizer for all displY modes (do i also have to provide a default panel fro each display?)
but nothing happened.
i'm not even sure if this is related to panelizer, or should i send it to openatrium?

DamienMcKenna’s picture

Status: Needs review » Needs work

This needs work.

skorzh’s picture

Status: Needs work » Needs review
FileSize
736 bytes

I debugged function hook_entity_update() in plugins/entity/PanelizerEntityDefault.class.php:933 and found a strange thing, when I revert a feature, in this function (line 949) in code:

foreach ($entity->panelizer as $view_mode => $panelizer) {

$panelizer variable in this case is an array, not an object.

This can be the cause of error. I created a patch what converted $panelizer variable to an object if it is an array.
It helps me in my case.

Please anybody test it.

DamienMcKenna’s picture

FileSize
726 bytes

A teeny-tiny tweak to korgik's patch that moves the new if() statement to the top of the foreach() loop. Anyone able to test this please?

manuelBS’s picture

Status: Needs review » Reviewed & tested by the community

#12 worked perfect for me!

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Needs review

@manuelBS: I'm glad you say it worked, but could you please confirm problem you were having before applying the patch and how the patch change it? Thanks.

DamienMcKenna’s picture

Status: Needs review » Fixed

I've tested out the patch in #13 and everything still worked, so I've committed it on the off-chance it does indeed resolve this problem. So, thanks to korgik for the patch!

Please re-open if the issue persists.

manuelBS’s picture

@DamienMcKenna I had the problem that sometimes when clearing the cache or reverting features containing panelizer information, I got the error described in the initial issue description. With this bug I was not able to clear the complete cache any more.

Status: Fixed » Closed (fixed)

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

MustangGB’s picture

Status: Closed (fixed) » Needs work

Pretty closely related I was getting an error on UPDATE, rather than INSERT.

The reason turns out to be that you shouldn't attempt to change the primary key when doing an update.

So the fix was this:

- $update = array('entity_type', 'revision_id', 'view_mode');
+ $update = array('entity_type', 'entity_id', 'revision_id', 'view_mode');

(Using MySQL 5.1.61)

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
1.04 KB

That's odd, it should have worked. Still, it isn't incorrect to include the 'entity_id' value. There was another case where "array('entity_type', 'revision_id', 'view_mode')" existed, so this patch changes both of them.

MustangGB’s picture

Yea, I changed both instances as well, not sure if you want someone else to RTBC this if you're not able to replicate, but the patch works for me and as you say, is not incorrect.

  • Commit 327d17e on 7.x-3.x by DamienMcKenna:
    Issue #1989100 by DamienMcKenna: Always include the entity_id when...
DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. Hopefully this will put an end to these oddities.

  • Commit 75c80a8 on 7.x-3.x by DamienMcKenna:
    By DamienMcKenna: Fixed the changelog note regarding #1989100.
    

Status: Fixed » Closed (fixed)

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

mglaman’s picture

For anyone coming across this... I discovered the issue when saving using Entity wrapper. My node bundle was set to provide revisioning, however I was not creating a revision when saving the node.

Then I found: http://drupal.stackexchange.com/questions/115710/why-entity-metadata-wra...

So I added the following line before ->save();

$node_wrapper->revision->set(1);

I usually don't post on closed threads, but the issue isn't technically Panelizer and I found this via Googling the error.

DamienMcKenna’s picture

@mglaman: Excellent info, thanks for posting that!

rattusrattus’s picture

Status: Closed (fixed) » Active

I am still getting this error when trying to update a node using Panelizer. The node type is configured to use a default panel for a number of core and custom view modes. I have tried using 7.x-3.x but unfortunately the issue persists.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-5714-6631-teaser' 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] => node [:db_insert_placeholder_1] => 5714 [:db_insert_placeholder_2] => 6631 [:db_insert_placeholder_3] => node:bond_job:default:teaser_extended [: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:1:{i:0;a:6:{s:10:"identifier";s:12:"Organisation";s:7:"keyword";s:17:"node_organisation";s:4:"name";s:50:"entity_from_field:field_organisation_ref-node-node";s:5:"delta";i:0;s:7:"context";s:9:"panelizer";s:2:"id";i:1;}} [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => teaser [:db_insert_placeholder_12] => bond-job-%node:sticky [:db_insert_placeholder_13] => H2 [:db_insert_placeholder_14] => 1 [:db_insert_placeholder_15] => a:0:{} ) in drupal_write_record() (line 7291 of /vagrant/bond/includes/common.inc).

Update: disabling panelizer for a custom view mode a created recently (teaser_extended) allows me to save the node but when i re-enable the same issue returns.

Update: My bad: I copied Panelizer config from one view mode to another by hacking the export and I'd not updated the view_mode property to the new view mode so this was completely unrelated to this issue.

rattusrattus’s picture

Status: Active » Closed (fixed)