Whenever we try to index content which has a value in the country field, we get the following error:

Drush command terminated abnormally due to an unrecoverable error. [error]
Error: Cannot use object of type Entity as array in
/path/to/drupal/install/includes/common.inc, line 5842

As you can see we are using drush to index the content.

When i delete the country field value - the indexing works fine.

Any idea why this might be happening?

Comments

gargsuchi’s picture

Issue summary: View changes
gargsuchi’s picture

OK, so I was able to pinpoint the exact line which was the culprit -
File - countries.fields.inc - line #59
$items[$id][$delta]['country'] = $country;

If I comment this out, the indexing goes through fine. Any idea if this has an adverse effect?

Alan D.’s picture

What code does line 5842 run?

Better yet, what is the trace where this happens?

In one of your module files (i.e. a custom one)

/**
 * Prints a debug trace.
 */
function debug_trace($return = FALSE) {
  $trace = debug_backtrace();
  $output = '';
  foreach ($trace as $n => $v) {
    $output .= $n . ': '
      . (empty($v['file']) ? '' : $v['file'] . ', ')
      . (empty($v['line']) ? '' : $v['line'] . ', ')
      . (empty($v['function']) ? '' : $v['function'] . ', ') . "\n";
  }
  if ($return) {
    return $output;
  }
  if (function_exists('dpm')) {
    dpm($output);
  }
}

And just before the error (Line 5841)

if (!is_array(????)) {
  watchdog('error', debug_trace(1))
  // This may allow it to continue, or maybe just return here.
  ???? = (array) ????
}

And copy and paste the watchdog results here.

Cheers

gargsuchi’s picture

What code does line 5842 run?

This is the first line in the drupal_render function

if (empty($elements) || (isset($elements['#access']) && !$elements['#access'])) {
     return '';
}

I added the following code above this line:

if (is_object($elements)) {
  print_r($elements); die;
}

And this gave me an output of an element of the type country.

Hope this helps.

Alan D.’s picture

for some reason, there is an incorrect FAPI call to the country item field. So the trace would help see where this is being called from.

So can you add this?

if (is_object($elements)) {
  $trace = debug_backtrace();
  $output = '';
  foreach ($trace as $n => $v) {
    $output .= $n . ': '
      . (empty($v['file']) ? '' : $v['file'] . ', ')
      . (empty($v['line']) ? '' : $v['line'] . ', ')
      . (empty($v['function']) ? '' : $v['function'] . ', ') . "\n";
  }
  print $output; die;
}
vaibhavjain’s picture

Alan,

I added the following code

function drupal_render(&$elements) {
  if (is_object($elements)) {
  print_r(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); die;
}

And the backtrace output is here

Array
(
    [0] => Array
        (
            [file] => /PATH/includes/common.inc
            [line] => 5945
            [function] => drupal_render
        )

    [1] => Array
        (
            [file] => /PATH/modules/field/field.module
            [line] => 1172
            [function] => drupal_render
        )

    [2] => Array
        (
            [file] => /PATH/includes/theme.inc
            [line] => 1161
            [function] => theme_field
        )

    [3] => Array
        (
            [file] => /PATH/includes/common.inc
            [line] => 5938
            [function] => theme
        )

    [4] => Array
        (
            [file] => /PATH/includes/common.inc
            [line] => 5945
            [function] => drupal_render
        )

    [5] => Array
        (
            [file] => /PATH/profiles/acquia/modules/apachesolr/apachesolr.index.inc
            [line] => 842
            [function] => drupal_render
        )

    [6] => Array
        (
            [file] => /PATH/profiles/acquia/modules/apachesolr/apachesolr.index.inc
            [line] => 287
            [function] => apachesolr_index_node_solr_document
        )

    [7] => Array
        (
            [file] => /PATH/profiles/acquia/modules/apachesolr/apachesolr.index.inc
            [line] => 242
            [function] => apachesolr_convert_entity_to_documents
        )

    [8] => Array
        (
            [file] => /PATH/profiles/acquia/modules/apachesolr/apachesolr.index.inc
            [line] => 125
            [function] => apachesolr_index_entity_to_documents
        )

    [9] => Array
        (
            [file] => /PATH/profiles/acquia/modules/apachesolr/apachesolr.index.inc
            [line] => 62
            [function] => apachesolr_index_entities_document
        )

    [10] => Array
        (
            [file] => /PATH/profiles/acquia/modules/apachesolr/apachesolr.admin.inc
            [line] => 1200
            [function] => apachesolr_index_entities
        )

    [11] => Array
        (
            [function] => apachesolr_index_batch_index_entities
        )

    [12] => Array
        (
            [file] => /usr/local/drush5/commands/core/drupal/batch.inc
            [line] => 149
            [function] => call_user_func_array
        )

    [13] => Array
        (
            [file] => /usr/local/drush5/commands/core/drupal/batch.inc
            [line] => 99
            [function] => _drush_batch_worker
        )

    [14] => Array
        (
            [file] => /usr/local/drush5/includes/batch.inc
            [line] => 93
            [function] => _drush_batch_command
        )

    [15] => Array
        (
            [file] => /usr/local/drush5/commands/core/core.drush.inc
            [line] => 1082
            [function] => drush_batch_command
        )

    [16] => Array
        (
            [function] => drush_core_batch_process
        )

    [17] => Array
        (
            [file] => /usr/local/drush5/includes/command.inc
            [line] => 334
            [function] => call_user_func_array
        )

    [18] => Array
        (
            [file] => /usr/local/drush5/includes/command.inc
            [line] => 208
            [function] => _drush_invoke_hooks
        )

    [19] => Array
        (
            [function] => drush_command
        )

    [20] => Array
        (
            [file] => /usr/local/drush5/includes/command.inc
            [line] => 175
            [function] => call_user_func_array
        )

    [21] => Array
        (
            [file] => /usr/local/drush5/drush.php
            [line] => 92
            [function] => drush_dispatch
        )

    [22] => Array
        (
            [file] => /usr/local/drush5/drush.php
            [line] => 61
            [function] => _drush_bootstrap_and_dispatch
        )

    [23] => Array
        (
            [file] => /usr/local/drush5/drush.php
            [line] => 16
            [function] => drush_main
        )

)