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?
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | panelizer-duplicates-1412022-27.patch | 1.26 KB | richardbporter |
| #22 | panelizer-duplicates-1412022-22.patch | 574 bytes | jrbeeman |
| #18 | panelizer-duplicates-1412022-18.patch | 603 bytes | jrbeeman |
| #10 | panelizer-duplicates-1412022-10.patch | 772 bytes | discipolo |
Comments
Comment #1
twistor commentedI get the same error with revisions turned off.
The problem I'm seeing in:
is that $entity->panelizer->revision_id is always empty because hook_field_attach_submit() sets $entity->panelizer to the default object.
Comment #2
mnlund commentedI'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.
Comment #3
exratione commentedYes, 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.
Comment #4
twistor commentedThis is also happening for Terms and Users, which also don't support revisions.
Comment #5
merlinofchaos commentedWait, 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?
Comment #6
twistor commentedOn latest dev with a new install:
Comment #7
merlinofchaos commentedOkay, 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...
Comment #8
exratione commentedThe fix in #7 works for my use case.
Comment #10
discipolo commentedreopening because i ran into this on the 3.x branch and fixed by applying the first part of #7 there.
Comment #11
merlinofchaos commentedI don't see how #10 helps -- it shouldn't pull the values from that location, so it seems like it's just adding confusion?
Comment #12
sylus commentedCan 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.
Comment #13
merlinofchaos commented#12: Can you provide exact reproduction steps? Likewise #10 it would help if you do the same.
Comment #14
sylus commentedHey @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.
Comment #15
merlinofchaos commentedOh 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?
Comment #16
merlinofchaos commentedAlso this query too, please?
select view_mode, count(*) from panelizer_defaults group by view_mode;Comment #17
sylus commentedAh! 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 ^_^
Comment #18
jrbeemanThe 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.Comment #19
MKorostoff commentedjrbeeman's patch in #18 solved this issue for me.
Comment #20
discipolo commentedi can verify that!
Comment #21
merlinofchaos commentedThat comparison can be collapsed to use empty instead of isset and not have to add a second clause.
Comment #22
jrbeemanSimplified patch attached, per #21
Comment #23
Hanz commentedHello 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
Comment #24
danielnolde commented#22 seems to work for me, but only on the dev (7.x-3.0-rc1+4-dev from 1348622087).
Comment #25
mgiffordThe patch in #22 applies still nicely to the git branch 7.x-3.x
Comment #26
merlinofchaos commentedCommitted and pushed #22.
Comment #27
richardbporter commentedI was still having this issue with the 7.x-3.x git branch. I changed three more instances of
if (!isset($panelizer->view_mode))toif (empty($panelizer->view_mode)). This fixed it for me.Thanks.
Comment #28
betz commented#27 worked for me too
Comment #29
smichel commented#27 did the trick for me.
Comment #30
betz commentedComment #31
merlinofchaos commentedCommitted and pushed #27. Thanks!
Comment #33
primozsusa commentedHi,
In the latest 7.x-3.x-dev this issue is still present...
Comment #34
neetu morwani commentedHi,
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).
Comment #35
neetu morwani commentedComment #36
fernly commentedIssue still present in latest dev (2014-Sep-08) when saving an existing node with node revision turned off.
Comment #37
Exploratus commentedI have this problem as well. Cannot add the action "Save Entity" to a rule. I get the error above. Please help
Comment #38
fox_01 commentederror 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
Comment #39
damienmckennaWould you mind testing again with the latest -dev release? Thanks.
Comment #40
damienmckennaBump. I'd like to get some feedback soon, I'm close to releasing v3.2.
Comment #41
kevinwalsh commentedThis worked for me (7.x-3.2-beta1). So nice to have VBO working again for panelized entities. Thanks!
Comment #42
damienmckennaThis should be working now.
Comment #44
emcniece commentedCurrently 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).Comment #45
damienmckenna@emcniece: site_template__* records are from Panels_Everywhere, not Panelizer. Please post some details in #2422189: Error when cloning a variant.
Comment #46
DrCord commentedThe patches from #22 and #27 are in the 3.5 release but I still get this error.