After running tests I see a number of field_config_entity_type left behind.

Comments

dave reid’s picture

Component: simpletest.module » field system

I'm guessing because field_sql_storage_schema() does a check for db_table_exists('field_config') during field_sql_storage_uninstall(), the field_config tables have already been removed, so that part of the schema does not get removed.

boombatower’s picture

Component: field system » simpletest.module

Narrowed it down to tearDown() in the DrupalWebTestCase.

The drupal_get_schema(NULL, TRUE); call doesn't return the table.

boombatower’s picture

Component: simpletest.module » field system

Cross-post

bjaspan’s picture

The field_config_entity_type is currently owned by field_sql_storage.module. I don't know why it wouldn't be dropped when that module is uninstalled.

I can't decide if that table and the function that populates it (_field_sql_storage_etid()) should be part of field.module or not. Other storage engines may not have any need to map entity types to ids, suggesting it belongs in field_sql_storage. However, any storage engine that uses the SQL database will need it, so not having it in field.module potentially causes duplicate code.

Comments welcome.

dave reid’s picture

StatusFileSize
new805 bytes

So...I can't believe it was this obvious:

/**
 * Implementation of hook_schema().
 */
function field_sql_storage_schema() {
  $schema = array();

  // Static (meta-data) tables.
  $schema['field_config_entity_type'] = array(
    'fields' => array(
      'etid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The unique id for this entity type',
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'An entity type',
      ),
    ),
    'primary key' => array('etid'),
    'unique keys' => array('type' => array('type')),
  );

  // Dynamic (data) tables.
  if (db_table_exists('field_config')) {
    $fields = field_read_fields();
    drupal_load('module', 'field_sql_storage');
>>>>  $schema = array(); <<<< THIS RESETS THE ARRAY AND AFFECTS THE UNINSTALL!!! ARG!
    foreach ($fields as $field) {
      $schema += _field_sql_storage_schema($field);
    }
  }
  return $schema;
}
dave reid’s picture

Title: SimpleTest leaves field_config_entity_type table behind » field_sql_storage_schema() does not remove the field_config_entity_type table
Status: Active » Needs review
boombatower’s picture

Status: Needs review » Reviewed & tested by the community

Fixes issue...wait for test results to confirm, but looks good.

Thanks for tracking that down Dave.

dave reid’s picture

Status: Reviewed & tested by the community » Needs review

For some reason now I'm getting just two tables left over after running the field tests:
simpletest792411field_data_revision_test_field_name
simpletest792411field_data_test_field_name

Investigating further to see why those aren't being removed now.

dave reid’s picture

StatusFileSize
new941 bytes

Managed to find what was going on. The two tables that were being left over was caused by the test FieldTestCase->testDeleteField where a field is marked as 'deleted' but the FieldAPI does not actually remove the tables. Then, in field_sql_storage_schema(), the function field_read_fields() is called to get all the field tables, but that function, by default does not include 'deleted' or 'inactive' fields. Luckily, there's an easy parameter change and all the tables uninstall cleanly now!

boombatower’s picture

Again, thanks for tracking that down.

bjaspan’s picture

Status: Needs review » Reviewed & tested by the community

Both changes look good. The first is an obvious bug, and for the second: deleted fields are supposed to be invisible to Field API callers but the tables do in fact still exist and so ought to be reported in the schema. RTBC.

boombatower’s picture

For anyone committing I believe you need #6 and #10.

dave reid’s picture

Actually, #10 contains the change in #6, so only #10 is needed.

boombatower’s picture

@#14 ahh..didn't see that before...it was late last night, guess I missed it.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks!

Status: Fixed » Closed (fixed)

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