programmatically taxonomy update node DrupalDefaultEntityController error When I programmatically create a taxonomy term and update node, in hook_node_presave() I have the following code:

$node-&gt;field_status_tags[LANGUAGE_NONE][]['tid'] = $value-&gt;tid;


I get the following error:


  Notice: Array to string conversion in DrupalDefaultEntityController->cacheGet() (line 369 of  includes\entity.inc).


This is the code I am using. I'm sure the value for tid is right.

/**
 * Implements hook_node_presave().
 */
function love_layout_node_presave($node) {
  /*
   *if ($node-&gt;nid &amp;&amp; $node-&gt;moderate) {
   *  // Reset votes when node is updated:
   *  $node-&gt;score = 0;
   *  $node-&gt;users = '';
   *  $node-&gt;votes = 0;
   *}
   */
  if($node-&gt;type == 'status') {

   $pattern = '/#([^\\#|.]+)#/';
   preg_match_all($pattern, $node-&gt;title, $matches, PREG_SET_ORDER);
   $node-&gt;field_status_tags[LANGUAGE_NONE] = array();
   foreach ($matches as $key =&gt; $value) {

      $term_name = $value[1];
      $term = taxonomy_get_term_by_name($term_name);
      if(!count($term)){
       $term = new stdClass();
       $term-&gt;vid = 1;
       $term-&gt;name = $term_name;
       taxonomy_term_save($term);
       $term = taxonomy_get_term_by_name($term_name);
       foreach ($term as $value) {
          //dpm($value,$key);
          $node-&gt;field_status_tags[LANGUAGE_NONE][]['tid'] = (int) $value-&gt;tid;
        }
      }else{
        foreach ($term as $key =&gt; $value) {
          //dpm($value,$key);
          $node-&gt;field_status_tags[LANGUAGE_NONE][]['tid'] = (int) $value-&gt;tid;
        }
      }
   }
   //dpm($node,'love_layout_node_presave-node');
  }
}
Basically I would think that $value->tid when you are using it is not a number but an array. Because I do the same assignment and it works.

So I suspect you are misusing the taxonomy term you created. This is how I created the taxonomy in a function:

function create_new_term($term_name, $vocabulary_id, $language = LANGUAGE_NONE, $i18n_tsid = 0){
  $tid = db_insert('taxonomy_term_data')
  -&gt;fields(array(
    'name'=&gt;$term_name,
    'vid'=&gt;$vocabulary_id,
    'language'=&gt;$language,
    'i18n_tsid'=&gt;$i18n_tsid,
  ))-&gt;execute();
  db_insert('taxonomy_term_hierarchy')
    -&gt;fields(array(
      'tid'=&gt;$tid,
      'parent'=&gt;0,
  ))
  -&gt;execute();
  print "Created new taxonomy term tid #".$tid." $term_name in $vocabulary_id&lt;br&gt;"."\n";
  return $tid;
}


And here is how I add that term:

$my_new_node-&gt;field_my_term['LANGUAGE_NONE'] [] ['tid'] = $returned_tid;


I hope this helps.