If you delete a field with field_delete_field you did create in your hook_install (like the node_example said http://api.drupal.org/api/drupal/developer--examples--node_example--node...) with a field defined in your own module. The tables of the field are not deleted because, in field_delete_field, field_info_field($field_name) returns NULL. In fact, in _field_info_collate_fields deleted fields (deleted on hook_disable), are not selected.

Here is a patch that corrects that behavior and permit having a module defining fields and using those fields.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

superbaloo’s picture

FileSize
873 bytes

May this patch will apply more smoothly

superbaloo’s picture

Issue tags: +Needs tests
superbaloo’s picture

Status: Active » Needs review
superbaloo’s picture

FileSize
831 bytes

Code cleanup thanks to chx

superbaloo’s picture

FileSize
784 bytes

Another code cleanup thanks to chx

superbaloo’s picture

FileSize
798 bytes

Another code cleanup

Status: Needs review » Needs work

The last submitted patch, 902794-field-deletion.patch, failed testing.

superbaloo’s picture

FileSize
1.15 KB

Forgot one variable usage :(

superbaloo’s picture

Status: Needs work » Needs review
superbaloo’s picture

FileSize
1.15 KB

patch format corrected

superbaloo’s picture

FileSize
1.12 KB

Unix EOL

superbaloo’s picture

FileSize
4.03 KB

Here we go with tests and comments

Status: Needs review » Needs work

The last submitted patch, 902794-field-deletion.patch, failed testing.

chx’s picture

Inline comments use // not /* even if multiline

The test, if you want to use the module page, needs a new module alas that hook_system_info_alter() the field_test module so that hidden becomes FALSE and so it becomes visible on the modules page and enable this little module with setUp. Alternatively you can call module_enable and module_disable directly and use the brand new ( four days ) $this->resetAll method after to reset everything.

yched’s picture

Status: Needs work » Postponed (maintainer needs more info)

I don't understand what this is about.
Can you provide a clear and (if possible) simple list of steps to reproduce the bug ?

superbaloo’s picture

Status: Postponed (maintainer needs more info) » Needs work

@chx: okay thank you for the tips

@yched:
If a module creates fields in its hook_install defined by itself, the fields would be created correctly.
If you disable it, fields becomes both inactive (because the field_module_disabled unset flag active) and when the cache is being rebuild (triggered at the end of field_modules_disabled) the fields are flagged as "deleted". So if in your module hook_uninstall you try to delete the fields you'd created in your hook_install, in field_delete_field when it looks for the field with field_info_field it gets NULL and fields never gets deleted. This way (if you use sql_storage) the table never gets deleted nor renamed and the records in field_config are not deleted. Then try to re-install the module, the fields gets recreated, the table is still here, you gets an sql error because of the not deleted table and the field will not be available at all.

If you want to check it by your-self, in the patch @#12 i did modify field_test module to trigger the bug.

  • apply the patch to field_test module
  • make it not hidden in field_test.info
  • enable it
  • ensure the field (field_test_test_field) is correctly created
  • disable it
  • uninstall it
  • check in database, the field should not be deleted
  • try to re-enable it
  • look at the error
Tor Arne Thune’s picture

Status: Needs work » Closed (duplicate)

Closing this as a duplicate of #943772: field_delete_field() and others fail for inactive fields, as the other issue has more recent activity and solutions.