So it seems that under certain data conditions the ID is not set because a PDOException is raised before multifield_field_presave is reached. This happens after multifield_field_insert.

Comments

e0ipso’s picture

StatusFileSize
new694 bytes

The suggested fix checks if the ID has been created and if not, then it calls multifield_get_next_id() to get one.

e0ipso’s picture

Status: Active » Needs review
e0ipso’s picture

StatusFileSize
new1.22 KB

Adding update code.

dave reid’s picture

Status: Needs review » Postponed (maintainer needs more info)

How would a PDO Exception be raised before hook_field_presave() can be called? At that point nothing should have actually saved it to the database?

e0ipso’s picture

I have not been using multifield for a while now, and details are pretty fuzzy but I was getting this pretty consistently. I'm sorry I cannot provide more context.

Thanks for looping back Dave I know it takes a lot of effort!

aron novak’s picture

Status: Postponed (maintainer needs more info) » Needs review

I can confirm that this is a valid issue. My case in a nutshell:
Devel Generate saves a node (likely not important)
In, hook_node_presave, using entity_metadata_wrapper (via patch https://www.drupal.org/files/issues/2041531-39-entity-api-support.patch), set the value of the multifield and let the process continue. The patch solved the scenario to me.

rudi teschner’s picture

I had quite some problems recently as well with missing ids.

I think it was caused in multifield_field_update() in file multifield.field.inc. why though ... i do not know.

    // Run each multifield pseudo-entity through hook_field_storage_pre_update().
    // @todo This invocation should probably be moved to a multifield_field_storage_pre_update().
    $skip_fields = array();
    foreach (module_implements('field_storage_pre_update') as $module) {
      $function = $module . '_field_storage_pre_update';
      $function('multifield', $pseudo_entity, $skip_fields);
    }

+    if (empty($pseudo_entity->id)) {
+      if (!empty($item->id)) {
+        $pseudo_entity->id = $item->id;
+      } else {
+        $pseudo_entity->id = multifield_get_next_id();
+      }
+    }

Have to see though if this solution has any siteeffects.