16

I've got fatal error EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7700 of .\includes\common.inc) when trying to access user/xyz.

I tried to retrieve info about the malformed node at line 7700, where the error message is built, thinks like :

if (!isset($entity->{$info['entity keys']['bundle']}) || $entity->{$info['entity keys']['bundle']} === '') {
 dpm($info);// or dpm($entity);
 throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
}

dpm($entity) returns an unexpected user object, and $info a huge qty of things.

Could somebody put me on the right way ?

I already read whatever I could find about Missing bundle property errors, but none helped solving.

dpm($entity) returns

uid (String, 2 characters ) 70
name (String, 9 characters ) John
pass (String, 55 characters ) $S$DUwPuOuDPiDL4nRTYXqc7a5uOfMKey7pyhOFUEKka1XM...
mail (String, 30 characters ) john@example.com
theme (String, 0 characters )
signature (String, 0 characters )
signature_format (String, 13 characters ) filtered_html
created (String, 10 characters ) 1396286331
access (String, 10 characters ) 1397146661
login (String, 10 characters ) 1396513460
status (String, 1 characters ) 1
timezone (NULL)
language (String, 2 characters ) fr
picture (NULL)
init (String, 30 characters ) john@example.com
data (Array, 5 elements)
roles (Array, 1 element)
og_user_node (Array, 0 elements)
message_subscribe_email (Array, 1 element)
field_bio (Array, 0 elements)
field_name_first (Array, 1 element)
field_name_last (Array, 1 element)
field_facebook_url (Array, 0 elements)
field_linkedin_url (Array, 0 elements)
field_twitter_url (Array, 0 elements)
user_trusted_contacts (Array, 1 element)
group_group (Array, 1 element)
group_access (Array, 1 element)
metatags (Array, 0 elements)
rdf_mapping (Array, 3 elements)
realname (String, 13 characters ) John Doe
content (Array, 13 elements)
entity_view_prepared (Boolean) TRUE
privatemsg_disabled (Boolean) FALSE
  • This is usually a pretty low level one that you can find out just by dpm()'ing the $entity. Make sure you are passing the entity itself -- and not a set of entities that entity load functions return. – AyeshK Apr 29 '14 at 17:20
  • 1
    I meant the it is basically checking if the bundle information exist before throwing the exception. If you could post the output of dpm($entity) (with the sensitive information blurred of course), that will help others to see what's wrong. – AyeshK Apr 29 '14 at 17:26
  • 3
    @Kojo The cause is actually a really simple one...something is calling entity_extract_ids('node', $var);, but instead of a node object for $var, it's passing a user object. If you have any custom or dev version contrib modules, try disabling them one by one to see it you can find the culprit – Clive Apr 29 '14 at 17:34
  • 2
    Yikes. dpm(debug_print_backtrace()); will be invaluable here. You can see what module started it all off by following the functions back to the beginning of the request – Clive Apr 29 '14 at 17:40
  • 1
    No worries, if you can get xdebug installed and configured with xdebug.collect_params = 4 that will also make your life a lot easier – Clive Apr 29 '14 at 17:47
27

The error:

EntityMalformedException: Missing bundle property on entity of type node.

happens, because your bundle property is malformed either on load or save, so Drupal can't find what type of bundle is it.

The logic of that Exception is:

// Explicitly fail for malformed entities missing the bundle property.
if (!isset($entity->{$info['entity keys']['bundle']}) || $entity->{$info['entity keys']['bundle']} === '') {
  // var_dump(debug_backtrace()); exit; // You may want this line to debug.
  throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
}

So basically value of $info['entity keys']['bundle'] (for node it's: type) can't be found in $entity object ($node->type for the node), therefore Drupal doesn't know with what kind of entity it's dealing with. So most likely your entity is invalid (e.g. you're loading something else instead) or it is just empty ($entity is NULL).


If you haven't modified any Drupal code, this potentially can be caused by variety of things (most likely by specific Drupal module bug), such as:

Here is the responsible code which is thrown by Drupal core (file: common.inc):

 if (!empty($info['entity keys']['bundle'])) {
    // Explicitly fail for malformed entities missing the bundle property.
    if (!isset($entity->{$info['entity keys']['bundle']}) || $entity->{$info['entity keys']['bundle']} === '') {
      throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
    }
    $bundle = $entity->{$info['entity keys']['bundle']};
  }

Debugging

If you don't recognise anything above, the easiest thing to debug that kind of error is by placing var_dump(debug_backtrace()); or dd(debug_backtrace()); (when Devel is on) before the actual throw new EntityMalformedException on the affected line in common.inc.

Note: Using dd() function from Devel will generate the debugging info to the file in your Drupal temp folder (temporary://drupal_debug.txt) with backtrace dump, otherwise could be too big and difficult to read when dumping on the screen. When using var_dump(), it's easier to call die(); after the call and check the dump in the view-source mode of the page.

If this is happening on node save, check this EntityMalformedException post at SO for more detailed instructions.


See also the following Drupal issue: #1778572 for more ideas.

  • 2
    kudos for a such detailed answer! I solved my issue a long time ago, but not doubt this will be helpful for a lot of people, me included. – Kojo Sep 8 '15 at 11:37
  • 3
    This is a fantastic answer! Deserves more upvotes. – Christian Apr 6 '16 at 6:26
  • I added dd(debug_backtrace()); to the affected line in front of throw new EntityMalformedException, made sure Devel is enabled and ran the drush command in cron that is throwing this error and am not getting any debugging output. What did I do wrong? Thanks! – Christia Feb 24 '17 at 22:37
  • 1
    Found it: the command created a file called drupal_debug.txt inside /tmp/drupal_theme/ where "drupal_theme" is the name of the drupal theme. Thanks for your excellent debugging help! – Christia Feb 24 '17 at 22:54
8

Thanks to Clive comments, I solved the issue as following.

Added ddebug_backtrace() where error occured (entity_extract_ids(), line 7700 of .\includes\common.inc ) to print the function call stack.

Then looking for anything unexpected in output, I found that a pane visibility rule might be the problem.

19: ctools_entity_field_value_ctools_access_check() (Array, 2 elements)
  file (String, 81 characters ) profiles\commons\modules\contrib\ctools\plugins...
  $...['19: ctools_entity_field_value_ctools_access_check()']['file']
    profiles\commons\modules\contrib\ctools\plugins\access\entity_field_value.inc:213
  args (Array, 3 elements)
    0 (Array, 2 elements)
      field_theme (Array, 1 element)
      //...

I had applied a patch on entity_field_value.inc a few days ago just to solve a visibility rule notice... and created a test visibility rule with a field_theme condition.

Now reverting patch or removing any pane visibility rule solved current EntityMalformedException bug... Powerful ddebug_backtrace() !

  • I tried this method and i got 1000's of line of code on front end. How do you see where the error is? – Sam Jul 3 '15 at 17:08
  • @Sam have a look at Kenorb answer, it might help you – Kojo Sep 8 '15 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.