When I try to edit and update a node with a field collection item, the node title sometimes didn't get updated. This however doesn't happen to body or other fields. Some investigation & debug led me to following logic:

1. i18n_node_form_submit -> node_save -> field_attach_update -> field_collection_field_update -> deleteRevision -> deleteHostEntityReference -> entity_save.

2. entity_save saves a node which is loaded with entity_load_single and when the node is not permanently saved to the database yet (the transaction in node_save is not finished yet), an outdated version of node is used and wrong node title is updated (the old title).

The node in question doesn't have revision and many others don't have either but this error didn't happen to them. Any clue about how to fix this?

Comments

Seems to be a duplicated issue: https://drupal.org/node/2052997

A possible hot fix (not to field collection code) is to implement another form submit handler, check if the node title is changed and update it. Here is an example:

<?php
/**
* Implements hook_form_FORM_ID_alter().
*/
function my_module_form_node_form_alter(&$form, $form_state) {
 
// Add our own submit handler
 
$form['#submit'][] = 'my_module_node_form_submit';
}
/**
* Submit handler for node edit form
*/
function my_module_node_form_submit($form, &$form_state) {
 
$values =& $form_state['values'];
 
$node = node_load($values['nid']);
 
// Fix the bug of node title not updated when node has field collection item
 
if ($node && $values['title'] !== $node->title) {
   
$node->title = $values['title'];
   
node_save($node);
  }
}
?>