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.
Comment | File | Size | Author |
---|---|---|---|
#20 | panelizer-n1989100-20.patch | 1.04 KB | DamienMcKenna |
#13 | panelizer-n1989100-13.patch | 726 bytes | DamienMcKenna |
#12 | panelizer-dublicate_entry-1989100-12.patch | 736 bytes | skorzh |
#1 | panelizer-1989100-duplicate-entry.patch | 575 bytes | devuo |
Comments
Comment #1
devuo CreditAttribution: devuo commentedComment #2
merlinofchaos CreditAttribution: merlinofchaos commentedYou'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?
Comment #3
devuo CreditAttribution: devuo commentedThe problem apparently arises from setting $update to an empty array. By setting $update as an empty array,
drupal_write_record()
will usedb_insert()
instead ofdb_update()
. The following also fixes the problem: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.Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedWell, 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?
Comment #5
devuo CreditAttribution: devuo commentedAnother 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.
Comment #6
merlinofchaos CreditAttribution: merlinofchaos commentedInteresting. What is the difference in Panelizer configuration between those view modes? That is likely going to be the culprit, somehow.
Comment #7
DamienMcKennaMight this be related to #2147303: panelizer_entity.view_mode is part of the primary key but is not specified to be 'not null'.?
Comment #8
DamienMcKennaComment #9
stockliasteroid CreditAttribution: stockliasteroid commentedI 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.
Comment #10
olak CreditAttribution: olak commentedi also have this bug, in openatrium. the error:
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?
Comment #11
DamienMcKennaThis needs work.
Comment #12
skorzhI debugged function
hook_entity_update()
inplugins/entity/PanelizerEntityDefault.class.php:933
and found a strange thing, when I revert a feature, in this function (line 949) in code:$panelizer
variable in this case is anarray
, not anobject
.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.
Comment #13
DamienMcKennaA 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?
Comment #14
manuelBS CreditAttribution: manuelBS commented#12 worked perfect for me!
Comment #15
DamienMcKenna@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.
Comment #16
DamienMcKennaI'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.
Comment #17
manuelBS CreditAttribution: manuelBS commented@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.
Comment #19
MustangGB CreditAttribution: MustangGB commentedPretty 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:
(Using MySQL 5.1.61)
Comment #20
DamienMcKennaThat'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.
Comment #21
MustangGB CreditAttribution: MustangGB commentedYea, 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.
Comment #23
DamienMcKennaCommitted. Hopefully this will put an end to these oddities.
Comment #26
mglamanFor 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();
I usually don't post on closed threads, but the issue isn't technically Panelizer and I found this via Googling the error.
Comment #27
DamienMcKenna@mglaman: Excellent info, thanks for posting that!
Comment #28
rattusrattus CreditAttribution: rattusrattus commentedI 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.
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.
Comment #29
rattusrattus CreditAttribution: rattusrattus commented