Set up a site with the 'Minimal' profile, enable comment module, and create a single content type. Edit its comment fields, and remove comment_body. Now create a second content type, and it dies with a FieldException: Attempt to create an instance of a field comment_body that doesn't exist or is currently inactive. in field_create_instance() (line 650 of /Users/jeff/Sites/d7b3/modules/field/field.crud.inc).
In a nutshell, if you only have one content type (or only one content type with comments enabled), and you delete comment_body, the field itself is deleted and subsequent attempts to define content types with comments die. Should we preserve the field itself, or have code that automatically re-creates it if it has been removed?
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | comment_body_field-974712-5.patch | 4.9 KB | yched |
| #5 | comment_body_field-974712-5.patch | 4.9 KB | yched |
Comments
Comment #1
montesq commentedBug is confirmed here... Just note you need also to enable field UI module to reproduce
Comment #2
yched commentedsounds like a dupe of #915906: Deleting node type with only instance of a field leaves the field in a strange zombie state
Comment #3
eaton commentedI'm not sure this is a duplicate: in that issue, deleting a content type leaves the field intact and un-reusable. In this situation, deleting the last field instance of comment body deletes the field itself, and turning on comments for a new content type results in comment.module blindly creating an instance of the no-longer-present body field. It needs to first check for the existence of the field it's about to add an instance of, and recreate it if it's been nuked...
Comment #4
yched commentedSorry, was reading too fast. This is related but obviously not a duplicate.
#915906-23: Deleting node type with only instance of a field leaves the field in a strange zombie state explains why we don't want to leave the field around when deleting the last instance.
comment.module needs to check if the field needs to be created before creating an instance.
Comment #5
yched commentedPatch + test.
Note : After #915906: Deleting node type with only instance of a field leaves the field in a strange zombie state gets in, the bug won't happen just when 'removing the last instance of the comment_body field in Field UI', but more generally with API calls to field_delete_instance() or node_type_delete() too (that's the whole point of that other thread).
The test therefore doesn't go through Field UI, and tests direct field_delete_instance() calls.
Being a little ahead of #915906: Deleting node type with only instance of a field leaves the field in a strange zombie state, it does the explicit field_delete_field() that field_delete_instance() currently doesn't do. Once that other patch gets in, the @todo in this patch will have to go away.
Comment #6
yched commentedThere are active bot clients and some patches get tested, while this one endlessly waits - WTF ?
Comment #7
carlos8f commentedI've merged this into #890128: Comment body missing if comment module enabled after a content type module, so marking as a duplicate for now. This patch has some nice clean-ups which make sense to build on, so maybe we can kill 2 birds with one stone :)