I'm creating some terms with the taxonomy_term_save function but i'm getting the following error:

EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7389 of /var/www/cmd/sitiocmd/code/includes/common.inc).

This didn't happen with the 7.7 version of Drupal core. Any help?

Issue fork drupal-1270340

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

    Comments

    girishmuraly’s picture

    Status: Active » Closed (duplicate)
    mburak’s picture

    I'm sorry but I applied the patch in commons.inc and still having the problem.
    This is the content of the entity when I get the error:

    stdClass Object
    (
        [name] => News
        [description] =>
        [vid] => 1
        [format] => plain_text
        [vocabulary_machine_name] =>
    )
    

    Perhaps something with the taxonomy module?

    Remon’s picture

    Status: Closed (duplicate) » Active

    Not sure if this issue is a duplicate. As stated above, the missing "taxonomy_term", neither media or file stuff.

    Remon’s picture

    Not sure if this issue is a duplicate. As stated above, the missing "taxonomy_term", neither media or file stuff.

    girishmuraly’s picture

    Status: Active » Postponed (maintainer needs more info)

    Would be better if more detail can be added about the issue, in particular how to reproduce it and how its different from the other already open issues.

    taxonomy_term_save() works. Perhaps check the vocabulary object or any other property of $term that you pass in. Its possible that the vocabulary is not yet created.

    damien tournoud’s picture

    Category: bug » support
    Status: Postponed (maintainer needs more info) » Fixed

    Thanks for your report, but this is not a bug.

    stdClass Object
    (
        [name] => News
        [description] =>
        [vid] => 1
        [format] => plain_text
        [vocabulary_machine_name] =>
    )
    

    ... because this is an invalid term. The vocabulary_machine_name is invalid. Feed a proper machine name or don't set this key.

    j0rd’s picture

    I get a similar error on my site (both 7.7 and 7.8).

    • Notice: Undefined index: taxonomy_term in taxonomy_field_formatter_view() (line 1419 of /home/www/site.tld/htdocs/modules/taxonomy/taxonomy.module).
    • EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7389 of /home/www/site.tld/htdocs/includes/common.inc).

    For me, it's very easy to duplicate. I have a node with the preview option enabled. If I preview, then preview again, I get the error I posted above.

    Not exactly too sure what the problem is, but may be related.

    Remon’s picture

    j0rd’s picture

    @Remon, thanks I'll take a look at those patches.

    Status: Fixed » Closed (fixed)

    Automatically closed -- issue fixed for 2 weeks with no activity.

    damienmckenna’s picture

    Another issue, #1290666: EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in function entity_extract_ids()., identified the same problem but had the following solution from fexmusicmutuz:

    [..] mymodule_taxonomy_term_page had to write return taxonomy_term_page ($term), rather than return taxonomy_term_page ($tid);

    giorgosk’s picture

    Status: Active » Closed (fixed)

    get same error after updating my site from nov 2011 version to lateset versions (drupal,commerce,views, entity, rules etc)

    EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7562 of /home/domain/public_html/dev/includes/common.inc).
    

    the error comes up when trying to edit a commerce product with taxonomy terms attached

    I traced with netbeans debugger and find that
    $info['entity keys']['bundle'] is "vocabulary_machine_name"
    and $entity does not contain "vocabulary_machine_name" as an attribute
    thus the expection is thrown all the time not letting me edit the product

    the following is DIRTY HACK that gets my work done untill this is resolved

    following modification does not throw the exception when the $entity_type is "taxonomy_term"
    which is always true in my case

    any suggestions ?

    
    function entity_extract_ids($entity_type, $entity) {
      $info = entity_get_info($entity_type);
    
      // Objects being created might not have id/vid yet.
      $id = isset($entity->{$info['entity keys']['id']}) ? $entity->{$info['entity keys']['id']} : NULL;
      $vid = ($info['entity keys']['revision'] && isset($entity->{$info['entity keys']['revision']})) ? $entity->{$info['entity keys']['revision']} : NULL;
    
      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']} === '') {
          if($entity_type == "taxonomy_term")
            $bundle = $entity_type;
          else 
            throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
        }else
          $bundle = $entity->{$info['entity keys']['bundle']};
      }
      else {
        // The entity type provides no bundle key: assume a single bundle, named
        // after the entity type.
        $bundle = $entity_type;
      }
    
      return array($id, $vid, $bundle);
    }
    
    
    
    giorgosk’s picture

    Version: 7.8 » 7.16
    Status: Closed (fixed) » Active

    active for anyone who has faced this before

    Aurochs’s picture

    Status: Closed (fixed) » Active

    Have same errors when addressing taxonomy terms pages but only those terms which are attached to nodes of non-ubercart content types...

    Notice: Undefined property: stdClass::$type в функции _node_extract_type() (строка 371 в файле /home/rostovpo/public_html/modules/node/node.module).
    Notice: Undefined property: stdClass::$nid в функции node_build_content() (строка 1358 в файле /home/rostovpo/public_html/modules/node/node.module).
    EntityMalformedException: Отсутствует связующее свойство у сущности типа node. в функции entity_extract_ids() (строка 7562 в файле /home/rostovpo/public_html/includes/common.inc).
    Н
    Aurochs’s picture

    I just solved the problem by editing context filter in terms page standard views form.
    Looks like it happened due to wrong view filtering.
    I chose all terms - any vocabulary but wanted to show ubercart field in the view so i guess that was the reason. No ubercart fields for the veiw at pages not belonging to ubercart
    so finally i made terms view to be valid only for ubercart pages and other pages to work via standard display

    kclarkson’s picture

    Version: 7.16 » 7.17

    I have just updated to Core 7.17 and am now receiving this message.

    There are so many issues regarding this I cannot keep them straight nor have I found a solution that works. Sad that I must restart a project :(

    giorgosk’s picture

    In my case it turned out that terms data were corrupted by a wrong import using feeds

    I put following code in my template.php and used it only when I was getting corrupted terms

    db_query("DELETE FROM `taxonomy_term_data` WHERE `taxonomy_term_data`.`vid` = 0");
    

    it deleted all terms that were not assigned to a vocabulary and it solved the problem

    might be helpful to someone

    kclarkson’s picture

    @GiorgosK

    Thanks for the quick reply. I looked at my database and it appears as though all of my terms have a VID but they don't have a UUID. I used your code and placed it into my template.php file but it just gave me an error.

    Any other suggestions ?

    Below is an error I am seeing when trying to create a "new" view the following popup shows:

    An AJAX HTTP error occurred.
    HTTP Result Code: 500
    Debugging information follows.
    Path: /admin/structure/views/view/tester/preview/page/ajax
    StatusText: error
    ResponseText: EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7646 of opentel/includes/common.inc).

    UPDATE: I am not receiving this error when I use fields in a view format option. Every other option, content, display suite, rendered entity etc.. shows this error. So I am going to assume it is an issue with entity's .

    kclarkson’s picture

    I found a fix today from another issue. #1281114: Database records not deleted for Term Reference Fields after Term is Deleted

    It uses the Taxonomy Orphanage Module because the taxonomy terms references are not deleted from the database it causes the error.

    There are other modules that do the same for other Entity reference as well. Def should link this page.

    William Aubert’s picture

    Hello,

    I have the same message on all my sites since I did the 7.17 update.
    The problem occurred only on the /taxonomy/term/all page (after the launching update.php file) :

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

    I tried the Taxonomy Orphanage Module and the field_reference_delete Module... but this has not solved the bug.

    This is strange because the taxonomy view worked fine before.

    kclarkson’s picture

    @william@studio

    Have you tried re-creating the taxonomy view ? Don't clone, just try creating the view after the update.

    William Aubert’s picture

    Thank you for the answer. This is the default core taxonomy/term% views. I disabled it and I created a new one, but I still have the error message.
    I tried to revert it, but the error is still there

    This error is on all my D7 sites.

    William Aubert’s picture

    I think I found it !

    After searching all weekend, I decided to restore the database for one of my sites. Luckily I had daily backups. So I think I found the problem this way.
    The correct version was more than 15 days, when I updated two modules including entityreference (7.x-1.0-rc3 to 7.x-1.0-rc4).
    I have not solved the problem on my other sites because I'd prefer only downgrade this module and don't restore all database.

    But I don't know the good way to safely downgrade only this modules. It could confirm that this module is causing my error.

    William Aubert’s picture

    Bad news, I think I spoke too soon...
    Everything seemed to work fine until I decide to disable a module this morning.

    When I update, disable or enable a module, the error appears again.
    This is very strange, I can't identify the causes of the problem...

    William Aubert’s picture

    Hello,

    I have not succeeded in solving my problem ...

    In database, I can see this watchdog line just after the error message on the site:
    wid:37301
    type:php
    %type: !message in %function (line %line of %file).
    severity:3
    link:
    location:http://www.domain.com/taxonomy/term/all

    -edit- Indeed, the problem occurred after updating several modules (include Meta tags 7.x-1.0-alpha8 to 7.x-1.0-beta2).
    -edit- My actual solution is to apply this patch.
    It looks working !

    kerasai’s picture

    This occurred for me while programmatically saving taxonomy terms using taxonomy_term_save(). The issue for me was not having a valid vid property set on the term object. Hope this helps you all figure this one out.

    sutriadi’s picture

    I dont have meta tags module installed, but i encountered this problems.
    I've drupal 7.19, entity module and entityreference module installed.

    sutriadi’s picture

    Version: 7.17 » 7.19
    LTech’s picture

    I have this error EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7633 of /home/xxxpublic_html/includes/common.inc).
    The website encountered an unexpected error. Please try again later.
    The site was fine until I installed the media module. So I uninstalled the media module and now when I try and use wp_blog I get the above error.

    marcoka’s picture

    same here. metatags disable. error gone

    deastlack’s picture

    EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7633

    I get the above error whe attempting to create a container of forum using the Advanced Forum module

    seaneffel’s picture

    Maybe related to all your problems, I have isolated my matching error messages down to bad term reference fields. At some point it started crashing out when attempting to preview nodes while a term reference field contained any value. If the field had no value, preview just fine.

    After isolating this problem to one specific term reference field, I then created an identical new field with the same name and configs. The new field previews without issue.

    Mad science alert! I then found my two fields in the "field_config_instance" table and I copied the "data" column from the new field into the bad field. Now the preview step works like a charm. I have a feeling that there is some old dead code in the bad field left over from a sloppy module update. I don't claim to understand it and I'm not smart enough to look at these strings of values and see what the bad egg is, but I thought I would post this for anyone else to learn from.

    Bad field:

    a:7:{s:5:"label";s:7:"Subject";s:8:"settings";a:1:{s:18:"user_register_form";b:0;}s:11:"description";s:134:"Select a term to describe the subject of this post.";s:8:"required";i:0;s:6:"widget";a:5:{s:6:"weight";s:2:"10";s:4:"type";s:14:"options_select";s:6:"module";s:7:"options";s:6:"active";i:1;s:8:"settings";a:0:{}}s:7:"display";a:2:{s:7:"default";a:4:{s:5:"label";s:5:"above";s:4:"type";s:6:"hidden";s:6:"weight";s:1:"7";s:8:"settings";a:0:{}}s:6:"teaser";a:5:{s:5:"label";s:5:"above";s:4:"type";s:28:"taxonomy_term_reference_link";s:6:"weight";s:1:"9";s:8:"settings";a:0:{}s:6:"module";s:8:"taxonomy";}}s:13:"default_value";N;}
    

    Good field:

    a:7:{s:5:"label";s:7:"Subject";s:6:"widget";a:5:{s:6:"weight";s:1:"9";s:4:"type";s:14:"options_select";s:6:"module";s:7:"options";s:6:"active";i:1;s:8:"settings";a:0:{}}s:8:"settings";a:1:{s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:28:"taxonomy_term_reference_link";s:8:"settings";a:0:{}s:6:"module";s:8:"taxonomy";s:6:"weight";i:18;}}s:8:"required";i:0;s:11:"description";s:51:"Select a term to describe the subject of this post.";s:13:"default_value";N;}
    

    Your field values will look different than mine, but maybe you'll see a pattern. Hope this helps someone.

    Yorgg’s picture

    I also have the same as #30
    EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() line 7633 of /includes/common.inc

    bpadaria’s picture

    @staminna

    https://sites.google.com/site/learnandmake/entitymalformedexception-miss...

    Solution mentioned at above link worked for me.

    orbrob’s picture

    I'm having this issue as well. It only happens on our production site which is using several caching layers: APC, memcache, & varnish. This is also on a LEMP stack (nginx). Pushing the most innocent 3 line module (hook_form_alter) can cause this. I don't think that hook had anything to do with it though, and this isn't the first time we've turned on a new module and seen this appearing in our logs endlessly. It's a major issue as the site comes to a hault on a server with 32 GB RAM & 12 dedicated cores. So, I started researching. I've implemented the change at #35 and have not had the chance to test turning on a module again.

    @seaneffel - I tried to look into the difference of those field instances and started by converting them into arrays to make them easier to look at. When I convert the "bad" string, I get:

    Notice: unserialize() [function.unserialize]: Error at offset 242 of 633 bytes in C:\xampp\htdocs\serialize.php on line 12

    So either it was a bad paste, or it's a bug. Whether or not that bug is related to this, I couldn't tell. But from the strings it looks like the "good" string is just missing the "teaser" view mode settings.

    EDIT: Forgot to mention, the way we fix it involves restarting php-fpm (for APC clearing), mysqld, and memcached. Sometimes a couple times and then it goes back to normal with the newly included module.

    marcopbazz’s picture

    #35 solution worked for me, thanks!

    Turies’s picture

    In my case it was fileaccess module.

    diff --git a/fieldaccess.module b/fieldaccess.module
    index d6effcf..41944b0 100644
    --- a/fieldaccess.module
    +++ b/fieldaccess.module
    @@ -276,7 +276,7 @@ function fieldaccess_field_access($op, $field, $obj_type, $object, $account) {
         if (user_access('bypass field access view restriction', $account)) {
           return TRUE;
         }
    -    if ($settings = fieldaccess_get_entity_fieldaccess_settings($op, $obj_type, $object, $field)) {
    +    if (is_object($object) && $settings = fieldaccess_get_entity_fieldaccess_settings($op, $obj_type, $object, $field)) {
           $context = array('op' => $op, 'field' => $field, 'object_type' => $obj_type, 'fieldaccess_settings' => $settings);
           $return = fieldaccess_grant_execute($settings['access_name'], $settings['settings'], $object, $account, $context);
         }
    dgtlmoon’s picture

    Yeah this seems to be caused by other modules

    lmeurs’s picture

    Issue summary: View changes

    I ran into the EntityMalformedException: Missing bundle property on entity of type taxonomy_term error as well, it took me half a day and it drove me nuts. Eventually the problem appeared to be... me!

    I use a field on a taxonomy vocabulary, in my template file I implemented MY_THEME_field(). In this function I render this field depending on the value of another field. I got the other field's items using:

      field_get_items('taxonomy_term', $variables['element']['#object'], 'OTHER_FIELDS_NAME');
    

    The passed element object is the taxonomy term the field belongs to.

    This worked fine, until I started using this field not only on a taxonomy vocabulary, but on a node type too. Now the element object is a node, but the passed entity type still is taxonomy_term which causes the error in my case.

    What helped me was placing the PHP's debug_print_backtrace() in the common.inc file right before the error is thrown to get a backtrace of all the functions.

    Best of luck to anybody struggling with this error!

    orbrob’s picture

    I installed https://drupal.org/project/taxonomy_orphanage and that fixed the problem. I put a few debugging statements in while this module did it's thing and found one node/field combo in particular where most of them were. It made sense because someone had just been "organizing" that area of the site. This error happened because the user went in and deleted the terms, but never went back and updated the nodes to remove the reference to that term. I imagine the error might not have happened if we were not also outputting the term reference field.

    I'm almost sure I'm missing another element in how this happens because I could only see the error happening after a cache clear. We run a stack with memcache & varnish to further complicate things and could never reproduce this in a dev environment with all caches disabled. Non the less taxonomy_orphanage has fixed the root of the problem.

    marcoka’s picture

    i tested deleted the taxonomy field causing this and recreated it, so no ghost/missing terms. i then realized it only happens with a taxonomy term reference field.
    related
    #1697284: EntityMalformedException: Missing bundle property on entity of type taxonomy_term

    my solution was to deleted the field AND the whole taxonomy vocabulary. reacreated both. now its working
    ok that did not fix it. but i now know why it worked. it worked as long as i displayed the field on the node page. the moment i removed the field on the "display" tab of the node type. well there is the error again.

    bfodeke’s picture

    #42 fixed my issue. Thanks for the obscure fix, I'd have never figured that out as a quick fix

    egfrith’s picture

    dgtlmoon’s picture

    swiftsystems’s picture

    Thank you GiorgosK for comment #13.

    The dirty hack worked beautifully for me lol.

    I also had the "vocabulary_machine_name" $info['entity keys']['bundle'] with the $entity->vocabulary_machine_name not being set.

    Here is a patch file for common.inc for those who need the quick fix.

    diff --git a/drupal/includes/common.inc b/drupal/includes/common.inc
    index ad2a345..7a511f4 100644
    --- a/drupal/includes/common.inc
    +++ b/drupal/includes/common.inc
    @@ -7785,9 +7785,17 @@ function entity_extract_ids($entity_type, $entity) {
       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)));
    +      if($entity_type == "taxonomy_term"){
    +        $bundle = $entity_type;
    +        $bundle_set_manually = true;
    +      }else{
    +        throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
    +      }
         }
    -    $bundle = $entity->{$info['entity keys']['bundle']};
    +    if(!isset($bundle_set_manually) || !$bundle_set_manually){
    +      $bundle = $entity->{$info['entity keys']['bundle']};
    +    }
    +
       }
       else {
         // The entity type provides no bundle key: assume a single bundle, named
    
    axhussain’s picture

    I was experiencing the same error with the following code:

    $term= array('vid' => $vid, 'name' => $node->field_author['und'][0]['value']);
    taxonomy_term_save($term);
    

    But I resolved the issue by turning $term into a class instead of an array:

    $term= new stdClass();
    $term->vid = $vid;
    $term->name = $node->field_author['und'][0]['value'];
    taxonomy_term_save($term);
    

    Hope that helps somebody else.

    subir_ghosh’s picture

    #19 fixed it for me. I was getting the error while accessing the Categories tab under Total Control Dashboard.

    bobburns’s picture

    Version: 7.19 » 7.64
    Category: Support request » Bug report
    Status: Closed (duplicate) » Active

    Still there in version 7.64

    Can someone commit this fix at #46 to core please ??

    It works fine