While using panelizer, I've discovered a use case that triggers an SQL error:

I create a node, select one of my default panels for it, and save. good so far.
I edit that node, and save again - it get the following error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-13-15' for key 'PRIMARY': INSERT INTO {panelizer_entity} (entity_type, entity_id, revision_id, name, no_blocks, css_id, css, pipeline, contexts, relationships, did) 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); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 13 [:db_insert_placeholder_2] => 15 [:db_insert_placeholder_3] => node:page:Call to Action layout [: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 ) in drupal_write_record() (line 6888 of /var/www/html/cwi/includes/common.inc).

While experimenting to find the cause of this error, I found the logic in PanelizerEntityDefault.class.php that sets up whether to insert a new record or not, using the $update array with drupal_write_record.

My use case, which I think must not have been accounted for, is that I'm saving an existing node with revisioning enabled, but not saving a new revision, while that node is using a default panel from panelizer.

From an editorial standpoint, I think that's a pretty normal use case, that a user would either neglect to create a new revision, or would intentionally choose to avoid a revision for an otherwise minor edit.

Under those circumstances, Panelizer is attempting to insert a new record in the panelizer_entity table where one already exists, when it should instead update the record it has.

Should the logic in PanelizerEntityDefault.class.php:467 or thereabouts be altered so that this case is handled, so $update has a value when drupal_write_record is called at the end of the hook_entity_update method?

I'm not sure I know exactly how that should best be accomplished, since we're handling entities and not just nodes...any thoughts?

Comments

twistor’s picture

I get the same error with revisions turned off.

The problem I'm seeing in:

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

is that $entity->panelizer->revision_id is always empty because hook_field_attach_submit() sets $entity->panelizer to the default object.

mnlund’s picture

Priority: Normal » Major

I'm seeing this too. The node is saved when you check create a new revision. Without that you encounter a duplicate key issue for the primary key.

exratione’s picture

Yes, I'm running into this also in the 2012-Jan-19 7.x-2.x-dev release. My workflow to replicate is:

- set up Panelizer for a content type, check all three checkboxes - 'Panelize', 'Provide Default Panel', and 'Allow Panel Choice'.
- create a single default
- then create a node of that content type
- then try to edit the node, which produces this error

As #1 says, revision_id is always empty/missing, leading it to try to insert a row rather than update the existing row - $update will be an empty array, and when passed to drupal_write_record() that gives you an insert.

    Notice: Undefined property: stdClass::$revision_id in PanelizerEntityDefault->hook_entity_update() (line 470 of /sites/all/modules/contrib/panelizer/plugins/entity/PanelizerEntityDefault.class.php).
    PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-1-1' for key 'PRIMARY': INSERT INTO {panelizer_entity} (entity_type, entity_id, revision_id, name, no_blocks, css_id, css, pipeline, contexts, relationships, did) 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); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => node:show:show [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => no_defaults_ipe [:db_insert_placeholder_8] => a:0:{} [:db_insert_placeholder_9] => a:0:{} [:db_insert_placeholder_10] => 0 ) in drupal_write_record() (line 6888 of /includes/common.inc).
twistor’s picture

This is also happening for Terms and Users, which also don't support revisions.

merlinofchaos’s picture

Wait, that revision_id error can't be happening with terms and users with the above code. It's not physically possible.

Please be sure you're using latest -dev?

twistor’s picture

On latest dev with a new install:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'user-1-0' for key 'PRIMARY': INSERT INTO {panelizer_entity} (entity_type, entity_id, revision_id, name, no_blocks, css_id, css, pipeline, contexts, relationships, did) 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); Array ( [:db_insert_placeholder_0] => user [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => user:user:asdfsafasdfasdfsdf [: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 ) in drupal_write_record() (line 6888 ...

merlinofchaos’s picture

Status: Active » Fixed

Okay, I see what's going on.

Field API is a little evil and it gives us a fake entity object which no longer has some data we loaded onto it. Which is partly why we were ovewriting it.

In anycase, fixed by this commit: http://drupalcode.org/project/panelizer.git/commit/6164f11643dd4e1f96571...

exratione’s picture

The fix in #7 works for my use case.

Status: Fixed » Closed (fixed)

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

discipolo’s picture

Version: 7.x-2.0-rc1 » 7.x-3.x-dev
Status: Closed (fixed) » Needs review
StatusFileSize
new772 bytes

reopening because i ran into this on the 3.x branch and fixed by applying the first part of #7 there.

merlinofchaos’s picture

I don't see how #10 helps -- it shouldn't pull the values from that location, so it seems like it's just adding confusion?

sylus’s picture

Can confirm there is a problem using panelizer 3.x-dev. Discovered this error using the panopoly distribution.

The patch does not resolve the error however.

merlinofchaos’s picture

#12: Can you provide exact reproduction steps? Likewise #10 it would help if you do the same.

sylus’s picture

Hey @merlinofchaos thanks for the reply sorry I should have done that :)

Going to any panelized node powered page in panopoly-dev and then saving twice yields the following:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /en/panels/ajax/ipe/save_form/panelizer%3Anode%3A3%3Apage_manager
StatusText: Service unavailable (with message)
ResponseText: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-3-3-' 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) 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] => node
[:db_insert_placeholder_1] => 3
[:db_insert_placeholder_2] => 3
[:db_insert_placeholder_3] =>
[:db_insert_placeholder_4] => 0
[:db_insert_placeholder_5] => page-page
[:db_insert_placeholder_6] =>
[:db_insert_placeholder_7] => ipe
[:db_insert_placeholder_8] => a:0:{}
[:db_insert_placeholder_9] => a:0:{}
[:db_insert_placeholder_10] => 2
[:db_insert_placeholder_11] =>
[:db_insert_placeholder_12] =>
[:db_insert_placeholder_13] => H2
[:db_insert_placeholder_14] => 1
)
in drupal_write_record() (line 7036 of /Users/sylus1984/Desktop/Sites/drupal_panopoly/includes/common.inc).

This might be a specific problem with panopoly though.

merlinofchaos’s picture

Oh now that's very interesting.

I can't immediately replicate the error, but there's something very interesting about yours. The view_mode is set to NULL, which should not be possible.

Can you do me a favor and run this query from your mysql administration program of choice?

select view_mode, count(*) from panelizer_entity group by view_mode;
merlinofchaos’s picture

Also this query too, please?

select view_mode, count(*) from panelizer_defaults group by view_mode;

sylus’s picture

Ah! Your a genius @merlinofchaos thanks for taking the time!

I took a look at the records and compared them to an earlier version of panopoly I have. It turns out I had re-exported the panopoly_pages.panelizer.inc feature and it was incorrectly generated. Reverting made the error go away. Not sure why but when I did your first query, it didn't list any view modes as opposed to untouched panopoly.

I will have to review to see what information I am missing from the generated panopoly_pages.panelizer.inc but at least I have a direction to go :)

However on a completely untouched panopoly installation saving twice does result in all information being removed but assigned the issue at: http://drupal.org/node/1737766 as currently not sure where it should reside

I can at least say I don't get the duplicate entry problem anymore ^_^

jrbeeman’s picture

StatusFileSize
new603 bytes

The attached patch addressed this issue for us, running 7.x-3.x branch. The issue, I believe, is that our exported Panelizer definitions all have view_mode = '';. This small change ensures that we properly check for an empty view mode.

MKorostoff’s picture

jrbeeman's patch in #18 solved this issue for me.

discipolo’s picture

i can verify that!

merlinofchaos’s picture

That comparison can be collapsed to use empty instead of isset and not have to add a second clause.

jrbeeman’s picture

StatusFileSize
new574 bytes

Simplified patch attached, per #21

Hanz’s picture

Hello everyone! Been having this same issue when trying to add content to a panelized content type. I tried merlinofchaos's #7 patch, but I get this error in my apache error log :

Fatal error: Declaration of PanelizerEntityNode::get_default_display() must be compatible with that of PanelizerEntityInterface::get_default_display() in /Library/WebServer/Documents/www/website/sites/all/modules/contrib/panelizer/plugins/entity/PanelizerEntityNode.class.php on line 12

Any insight?

Thanks

danielnolde’s picture

#22 seems to work for me, but only on the dev (7.x-3.0-rc1+4-dev from 1348622087).

mgifford’s picture

The patch in #22 applies still nicely to the git branch 7.x-3.x

merlinofchaos’s picture

Status: Needs review » Fixed

Committed and pushed #22.

richardbporter’s picture

Priority: Major » Normal
Status: Fixed » Needs review
StatusFileSize
new1.26 KB

I was still having this issue with the 7.x-3.x git branch. I changed three more instances of if (!isset($panelizer->view_mode)) to if (empty($panelizer->view_mode)). This fixed it for me.

Thanks.

betz’s picture

#27 worked for me too

smichel’s picture

#27 did the trick for me.

betz’s picture

Status: Needs review » Reviewed & tested by the community
merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed #27. Thanks!

Status: Fixed » Closed (fixed)

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

primozsusa’s picture

Hi,
In the latest 7.x-3.x-dev this issue is still present...

neetu morwani’s picture

Hi,
Even I am using latest dev version of panelizer module. Still I get this error when i programatically change the values of the field in the node and call node_save($node).

neetu morwani’s picture

Status: Closed (fixed) » Active
fernly’s picture

Issue still present in latest dev (2014-Sep-08) when saving an existing node with node revision turned off.

Exploratus’s picture

I have this problem as well. Cannot add the action "Save Entity" to a rule. I get the error above. Please help

fox_01’s picture

error still exist in latest 7.x-3.x-dev. i have tried turning on and of the revisioning module and the core node revision function. nothing helps

damienmckenna’s picture

Would you mind testing again with the latest -dev release? Thanks.

damienmckenna’s picture

Bump. I'd like to get some feedback soon, I'm close to releasing v3.2.

kevinwalsh’s picture

This worked for me (7.x-3.2-beta1). So nice to have VBO working again for panelized entities. Thanks!

damienmckenna’s picture

Status: Active » Fixed

This should be working now.

Status: Fixed » Closed (fixed)

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

emcniece’s picture

Currently hitting this issue with 7.x-3.2-beta1+19-dev

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'site_template__basic_sidebar_layout' for key 'name': INSERT INTO {page_manager_handlers} (name, task, subtask, handler, weight, conf) 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); Array ( [:db_insert_placeholder_0] => site_template__basic_sidebar_layout [:db_insert_placeholder_1] => site_template [:db_insert_placeholder_2] => [:db_insert_placeholder_3] => panel_context [:db_insert_placeholder_4] => -27 [:db_insert_placeholder_5] => a:12:{s:5:"title";s:20:"Basic Sidebar Layout";s:9:"no_blocks";i:1;s:8:"pipeline";s:8:"standard";s:22:"body_classes_to_remove";s:0:"";s:19:"body_classes_to_add";s:0:"";s:6:"css_id";s:0:"";s:3:"css";s:0:"";s:8:"contexts";a:0:{}s:13:"relationships";a:0:{}s:4:"name";s:20:"basic_sidebar_layout";s:6:"access";a:2:{s:7:"plugins";a:1:{i:0;a:3:{s:4:"name";s:5:"front";s:8:"settings";N;s:3:"not";b:1;}}s:5:"logic";s:3:"and";}s:3:"did";s:2:"17";} ) in drupal_write_record() (line 7261 of /var/www/clients/client0/web28/web/includes/common.inc).

damienmckenna’s picture

@emcniece: site_template__* records are from Panels_Everywhere, not Panelizer. Please post some details in #2422189: Error when cloning a variant.

DrCord’s picture

The patches from #22 and #27 are in the 3.5 release but I still get this error.