mongdb_field_storage does not store fields when called via hook_entity_update, resulting in entites being stored in MongoDB that have no fields.

The reason for this is as follows:

1. mongodb_field_storage_entity_update implements hook_entity_update
2. This in turn calls mongodb_field_storage_field_storage_write($entity_type, $entity, NULL, array(), TRUE);
2A. Note that above, we are passing array() which corresponds to $fields in mongodb_field_storage_field_storage_write
3. mongodb_field_storage_field_storage_writeattaches fields to the entity using foreach ($fields as $field_id)
4. Because $fields is empty, the entity is saved with no fields data!

Proposed solution:

Remove mongodb_field_storage_entity_update - there is no need for this hook as far as I can see

Comments

phayes’s picture

We should also remove mongodb_field_storage_entity_insert

chx’s picture

Status: Active » Postponed (maintainer needs more info)

I am not sure what the problem is. There is a wall of text on the top of mongodb_field_storage_field_storage_write regarding entity writes and statics. In short, if your entity doesn't call field_attach_insert/update before invoking hook_entity_update/hook_entity_insert then this is the failsafe. Otherwise, field_attach_insert/update will write the fields info. Tell me what's not working given this.

phayes’s picture

I'm seeing behavior whereby node-saves are writing to mongodb *twice*. The first one, field_attach_insert/update works fine. The second, hook_entity_insert/update, writes the node, but without the fields (for the reasons detailed in the issue desc). This results in nodes being saved to mongoDB without fields. I'll see if I can dig in a little more and come to a better solution.

chx’s picture

That's weird -- obviously this does not happen to a lot of people or we would have bug reports all over. Care to dump backtraces (no arguments, no objects, just the list of callers)? Something weird is happening there.

phayes’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Hmmm.. Now I'm unable to reproduce... Marking as won't fix. If I can reproduce it I will re-open.

rydje’s picture

Hello,

I'm reproducing this problem using Bean module with State machine.

When I'm saving my bean entity my fields are correctly wrote in the first invoke of hook_field_storage_write

But when the hook_entity_update is invoked, my fields are removed because of the mongodb_field_storage_field_storage_write call with no array supplied.

I resolved this problem by implementing an entity_update on a heavier custom node and retrieves fields using the same code as field_attach_update (without reinvoking the update hooks)

I'm note sure is this will do the trick, I'm still new to Drupal and mongoDB module.

rydje’s picture

Issue summary: View changes

formatting