By Kojo


2014-04-29 17:09:58 8 Comments

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 ) [email protected]
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 ) [email protected]
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

2 comments

@kenorb 2015-09-08 11:13:21

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.

@Kojo 2015-09-08 11:37:43

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.

@Christian 2016-04-06 06:26:49

This is a fantastic answer! Deserves more upvotes.

@Christia 2017-02-24 22:37:31

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 2017-02-24 22:54:19

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!

@Kojo 2014-04-30 16:25:44

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() !

@Sam 2015-07-03 17:08:30

I tried this method and i got 1000's of line of code on front end. How do you see where the error is?

@Kojo 2015-09-08 14:47:24

@Sam have a look at Kenorb answer, it might help you

Related Questions

Sponsored Content

6 Answered Questions

[SOLVED] Debug EntityFieldQuery?

  • 2012-07-10 08:30:12
  • Letharion
  • 14005 View
  • 26 Score
  • 6 Answer
  • Tags:   7 entities debugging

1 Answered Questions

[SOLVED] How do I debug "unexpected % in php_eval()"?

  • 2017-01-03 08:54:53
  • Kojo
  • 229 View
  • 0 Score
  • 1 Answer
  • Tags:   debugging

1 Answered Questions

[SOLVED] How to debug closed connection error

  • 2016-02-21 09:52:14
  • Josh
  • 23 View
  • 0 Score
  • 1 Answer
  • Tags:   debugging

1 Answered Questions

[SOLVED] How to implement a multiple (AJAX) field collection with the FAPI

  • 2013-08-29 15:58:05
  • B2F
  • 715 View
  • 0 Score
  • 1 Answer
  • Tags:   7 ajax entities

0 Answered Questions

How debug Drupal 8 errors

  • 2014-04-16 11:37:35
  • Alexei Rayu
  • 1316 View
  • 0 Score
  • 0 Answer
  • Tags:   debugging

0 Answered Questions

error "EntityMalformedException" when creating a node as guest

1 Answered Questions

[SOLVED] What are valid entity_id and entity_type values for node content?

  • 2014-12-02 18:27:27
  • Andrew Wasson
  • 240 View
  • 1 Score
  • 1 Answer
  • Tags:   nodes entities

1 Answered Questions

[SOLVED] Krumo output with debug()

  • 2014-03-11 10:05:37
  • undersound
  • 147 View
  • 0 Score
  • 1 Answer
  • Tags:   debugging

2 Answered Questions

[SOLVED] How can I print a field from a referenced entity in my theme?

  • 2013-04-21 05:55:03
  • Peter Clemence
  • 3040 View
  • 4 Score
  • 2 Answer
  • Tags:   theming entities

4 Answered Questions

[SOLVED] How to debug Drupal Forms

  • 2011-10-12 10:28:54
  • AgA
  • 933 View
  • 3 Score
  • 4 Answer
  • Tags:   6 debugging

Sponsored Content