It took me a long time to track this issue down to Organic Groups.

I'm not 100% certain the the issue began exactly when I upgraded Drupal to 7.14, but it seems likely.

Here's the issue. When I attempt to delete some users (not others) via Drupal's 'People' page, I receieve this error:

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?id=1176&op=do StatusText: Service unavailable (with message) ResponseText: EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7539 of /localhost/druce/docroot/includes/common.inc).

OG entity reference fields have been added to the user object, and these fields cause the problem. Removing the fields, disabling og, or disabled entity reference will each fix this problem (not that they are really viable options for me).

I can't seem to figure out why this problem occurs when deleting some users, but not other. The users seem to be the same in the database, but there must be a difference.

I'll continue to look into this, but given how difficult it was to track the source of this issue to OG, I wanted to post an issue as a reference.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

grasmash’s picture

I did a backtrace and found that when og.module calls entity_extract_ids($group_type, $group) on line 1652, $group is not populated with the intended entity-- it is empty.

 $group = entity_load_single($group_type, $gid);
  dpm($group);
  list(,, $group_bundle) = entity_extract_ids($group_type, $group);

Using this to debug, I see that $group_type and $gid are set appropriate to real, valid values. But for some reason, nothing is being returned by entity_load_single.

grasmash’s picture

Yeah... this is very weird. I can't seem to load the group node from the database via any means apart from the command line.

These all fail:

    $group = entity_load_single($group_type, $gid);
    $group = entity_load($group_type, array($gid), array(), TRUE);
    $group = node_load((int)$gid, NULL, TRUE);
    $group = db_query("SELECT * FROM {node} n WHERE n.nid = :gid", array(':gid' => $gid))->fetchObject();
    
    dpm($group);

Don't know if this could have something to do with caching or bootstrapping?

Totally puzzled.

grasmash’s picture

Ok, I at least determined what differentiates the problematic users from others. Each user that cannot be deleted is the author of an organic group! Changing the ownership of the group to another user opens up the ability to delete the users en masse, so that's a start!

pav’s picture

I don't think this is an OG issue.

http://drupal.org/node/1565346

s.Daniel’s picture

@madmatter23: If you change the owner back to the original user does that fix the error as well?

Also: Check your database node table for nodes with an empty type attribute.

btorgan’s picture

I don't mean to be repetitive but there is a very similar issue posted for devel module (see issue #1902832 http://drupal.org/node/1902832#comment-7244672). The issue appeared on my site only when devel and og were working together. It is very frustrating as I am trying to build a large group site and could really use the devel generate with og. (Using ver 7.21)

btorgan’s picture

Issue summary: View changes

adding detail to error message

alan-ps’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
457 bytes

I got a similar error (function og_get_user_roles) when worked with termstatus and OG, namely:

EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7734 of /var/www/site.loc/includes/common.inc).

As was described in the first comment: entity_load_single returns FALSE.

If core calls hook_query_TAG_alter during entity_load, then anything that calls entity_load (in this case OG) should expect that the query could have been altered.

So, we should add check in this case. Patch attached.

geek-merlin’s picture

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

This resolved my issue. I deleted a node and there was a cache to deal with node access that seemed to providing the deleted node's gid to this function.

joelpittet’s picture

Maybe didn't update the moderation for the user yet, as in the cron or something didn't update og_membership table?
og_moderation_node_grants() called og_get_entity_groups('user', $account) which loaded the stale group from the og_membership table.

Vanitha Sophia’s picture

I found the same issue when i upgraded the organic groups module of version 7.x-2.10 causing the error 'EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids()'

After debugging found in line 1830
if (is_numeric($entity)) {
$entity = entity_load_single($entity_type, $entity);
}
list(,, $bundle) = entity_extract_ids($entity_type, $entity);

Which actually worked with these
$wrapper = entity_metadata_wrapper($entity_type, $entity);
$bundle = $wrapper->getBundle();

Added the patch for it.
og-mising_bundle_property-1559766-12.patch

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: og-mising_bundle_property-1559766-12.patch, failed testing. View results

scottAtRoot802’s picture

In my case, the issue was not from deleting users but rather from missing (or previously deleted) nodes, that were referenced by entity reference. What fixed it for me was checking if the entity was empty before calling entity_extract_ids().

function og_is_group($entity_type, $entity) {
  if (is_numeric($entity)) {
    $entity = entity_load_single($entity_type, $entity);
  }
  if (!empty($entity)) { // Check for missing entity
    list(,, $bundle) = entity_extract_ids($entity_type, $entity);
    if (!field_info_instance($entity_type, OG_GROUP_FIELD, $bundle)) {
      return variable_get("og_is_group__{$entity_type}__{$bundle}", FALSE);
    }
    $items = field_get_items($entity_type, $entity, OG_GROUP_FIELD);

    return !empty($items[0]['value']);
  }
}
MegaChriz’s picture

MegaChriz’s picture

Title: EntityMalformedException when deleting users after 7.14 upgrade » EntityMalformedException when deleting users in og_get_user_roles()

Changed title to better reflect differences with #2900273: Deleted groups causes EntityMalformedException in og_is_group()..

MegaChriz’s picture

Title: EntityMalformedException when deleting users in og_get_user_roles() » EntityMalformedException when deleting users, in og_get_user_roles()
dmundra’s picture

Status: Needs work » Needs review

#7 resolved our issue as well. We are using the og_get_user_roles function in many custom modules and we were getting the EntityMalformedException error when handling orphaned content (similar to @signalScott).

I am not sure about #12 so I am hiding it for now.

ahsanalishahid’s picture

#14 worked well for me. I was suspecting that the issue was caused by some deleted nodes.