Repro:

Install Drupal minimal profile.
Install node_example from the Developer Examples module.
Use admin/modules/uninstall or devel/reinstall (Develop Module) to re-install node_example.

Result:

EntityFieldQueryException: Field storage engine not found. in EntityFieldQuery->queryCallback() (line 1172 of C:\something\something\darkside\drupal\includes\entity.inc).

If I add the following code to the minimal.install

  // Insert default pre-defined node types into the database. For a complete
  // list of available node type attributes, refer to the node type API
  $types = array(
    array(
      'type' => 'page',
      'name' => st('Default Page'),
      'base' => 'node_content',
      'description' => st("Use <em>basic pages</em> for your static content, such as an 'About us' page."),
      'custom' => 1,
      'modified' => 1,
      'locked' => 0,
    ),
  );


  foreach ($types as $type) {
    $type = node_type_set_defaults($type);
    node_type_save($type);
    node_add_body_field($type);
  }

.. and repeat the same test, there is no error.

Comments

fago’s picture

Status: Active » Closed (works as designed)

There is no code of the entity api module involved.

DrMiaow’s picture

Yes. Not in the code I provided.

I suspect that not having a base page defined at the install of drupal seems to trigger something down the line.

The error I am getting is in entity.inc

bgano’s picture

Project: Entity API » Drupal core
Version: 7.x-1.x-dev » 7.12
Component: Core integration » field system
Status: Closed (works as designed) » Patch (to be ported)

The issue appears to originate in field_purge_batch. There are cases where the call to field_info_field_by_id returns an empty result, which is then used to generate an invalid query, which is where the exception occurs. If you check the result of field_info_field_by_id before building/executing the query, the purge works as expected. I haven't tracked down what causes the empty result.

Here's the working code:

function field_purge_batch($batch_size) {
  // Retrieve all deleted field instances. We cannot use field_info_instances()
  // because that function does not return deleted instances.
  $instances = field_read_instances(array('deleted' => 1), array('include_deleted' => 1));

  foreach ($instances as $instance) {
    // field_purge_data() will need the field array.
    $field = field_info_field_by_id($instance['field_id']);
    // Retrieve some entities.
// BEGIN NEW CODE
    $results = FALSE;
    if ($field) {
      $query = new EntityFieldQuery();
      $results = $query
        ->fieldCondition($field)
        ->entityCondition('bundle', $instance['bundle'])
        ->deleted(TRUE)
        ->range(0, $batch_size)
        ->execute();
    }
// END NEW CODE
    if ($results) {
      foreach ($results as $entity_type => $stub_entities) {
        field_attach_load($entity_type, $stub_entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1));
        foreach ($stub_entities as $stub_entity) {
          // Purge the data for the entity.
          field_purge_data($entity_type, $stub_entity, $field, $instance);
        }
      }
    }
    else {
      // No field data remains for the instance, so we can remove it.
      field_purge_instance($instance);
    }
  }

  // Retrieve all deleted fields. Any that have no instances can be purged.
  $fields = field_read_fields(array('deleted' => 1), array('include_deleted' => 1));
  foreach ($fields as $field) {
    $instances = field_read_instances(array('field_id' => $field['id']), array('include_deleted' => 1));
    if (empty($instances)) {
      field_purge_field($field);
    }
  }
}
bgano’s picture

Status: Patch (to be ported) » Active

In the interest of completeness, in cases where field_info_field_by_id returns an empty result set, it also gives a warning, because $info['fields'] does not exist. field_info_field_by_ids has the same issue. The following works, but I suspect there might be a deeper issue with _field_info_collate_fields.

function field_info_field_by_id($field_id) {
  $info = _field_info_collate_fields();
  if (isset($info) && isset($info['fields']) && isset($info['fields'][$field_id])) {
    return $info['fields'][$field_id];
  }
}
function field_info_field_by_ids() {
  $info = _field_info_collate_fields();
  if (isset($info) && isset($info['fields'])) {
    return $info['fields'];
  }
}
bgano’s picture

In the interest of completeness, in cases where field_info_field_by_id returns an empty result set, it also gives a warning, because $info['fields'] does not exist. field_info_field_by_ids has the same issue. The following works, but I suspect there might be a deeper issue with _field_info_collate_fields.

function field_info_field_by_id($field_id) {
  $info = _field_info_collate_fields();
  if (isset($info) && isset($info['fields']) && isset($info['fields'][$field_id])) {
    return $info['fields'][$field_id];
  }
}
function field_info_field_by_ids() {
  $info = _field_info_collate_fields();
  if (isset($info) && isset($info['fields'])) {
    return $info['fields'];
  }
}
star-szr’s picture

Version: 7.12 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.