Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
field system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
14 Dec 2010 at 16:19 UTC
Updated:
31 Dec 2010 at 01:40 UTC
Jump to comment: Most recent file
Comments
Comment #1
jhodgdonUmmm... What are you saying needs to be documented? I'm confused.
Comment #2
sven.lauer commentedSorry for not being clear:
If you give file_info_field the name of a field that is inactive (but not deleted), the function will return nothing.
As of now, the documentation only states "$field_name can only refer to a non-deleted field." which to me suggests that it could refer to a non-deleted, but inactive field.
So, I guess the sentence should be changed to "$field_name can only refer to a non-deleted, active field."
It might be that the original intent was to return a field array also for inactive fields (for then, the function can be used to check if a certain field exists before attempting to create it). If that is the case, the implementation needs to be changed.
Comment #3
jhodgdonThanks...
That sounds like the right change to the documentation. At this point, I don't think we will change the function behavior. But let's see if we can get one of the Field maintainers to comment.
Comment #4
rfaysubscribe.
I'm no expert at this, but am certainly a hater of inactive fields :-) This issue probably goes more deeply into the heart of the "Drupal doesn't really know what to do with inactive fields" territory than just a docs change on this function.
Comment #5
yched commentedThat's right, field_info_field() only returns active, non-deleted fields - that's the intended behavior.
Comment #6
sven.lauer commentedOkay, then it is only the documentation that needs to be updated.
However, given this intended behavior,
field_delete_fieldonly deletes instances of fields that are active, not those of fields that are inactive.Calling
field_delete_fieldon an inactive field will mean that the field itself will be marked for deletion, but not its instances. Also, unless I am very much mistaken, the data for the field will also not get marked for deletion. This is so becausefield_delete_fieldusesfield_info_fieldto figure out what the storage engine is, and what bundles have instances. Since, on an inactive module,field_info_fieldwill return void, theissettests infield_delete_fieldwill evaluate toFALSE.So if the field to be deleted is active,
field_delete_fieldwill mark the field for deletion, as well as all its instances and data. If the field is inactive, only the field will be marked for deletion. This seems like inconsistent behavior to me, and should at least be documented.Given the current behavior, deleting an inactive field will always result in orphaned instances/data---is that really what is intended? For one thing, it makes
field_delete_fieldpretty useless in uninstall hooks (where the fields will always be inactive, because the module will be deactivated first). Maybe I am missing something, or am trying to usefield_delete_fieldwrongly.Comment #7
jhodgdonWhat does "inactive" mean for a field??? I thought probably it meant it had no instances, but maybe not. Maybe this should also be documented somewhere?
Comment #8
rfayIMO this is a perpetual problem with fields, because no adequate solution to inactive fields has ever been chosen. See D6 issues #863226: UI element to delete or re-activate inactive field instances and #649298-48: Features install/revert does not remove additional fields from content type already stored in the db
Comment #9
jhodgdonWhat does "inactive" mean then?
And what about #6?
Comment #10
sven.lauer commentedHm, I do understand why a function like the current
field_info_fieldcan be useful for certain things, but it seems to be a really bad idea to use it in something likefield_delete_field... essentially that means that there is no way (except directly going into the database) for a module to delete its fields on uninstall. Or at least, to do so without orphaning instances and data. That is not too bad (==does not directly break) if the field in question does not have its own table, but if it does, re-activating the module will throw an error for trying to create a table that already exists.As it stands, at least one core module (comments) uses field_delete_field and so orphans it's instances on uninstall.
Comment #11
yched commentedFields are inactive if the module that defines the field type is disabled, or if the module that defines their storage backend is disabled.
Disabled fields have always been a massive pain to deal with, because, the module being disabled, there's really not much we can do with them.
I agree field_delete_field() is currently not really bulletproof when called on an inactive field. Care to open a separate issue ?
Comment #12
sven.lauer commentedI was about to open a separate issue when I found #943772: field_delete_field() and others fail for inactive fields.
There is a patch, but no activity since October 23 ...
Comment #13
jhodgdonOK. Barring that other issue making changes to field_info_field(), it sounds like we should at least fix the doc for that function so that it reflects what the function does, which is operate only on active, non-deleted fields. As suggested by Sven earlier:
$field_name can only refer to a non-deleted, active field.
Should we go ahead and make that doc change?
Comment #14
sven.lauer commentedI doubt that the other issue will make a change to field_info_field() ... the point of this function really seems to be to only return fields that "you can do something with". The patch in this issue basically avoids using field_info_field() for the deletion stuff, which is as it should be, in my view.
Maybe we should also add a reference to field_read_fields() as a means to also get deleted and/or inactive fields?
Comment #15
jhodgdonOK. Here's a proposed doc patch for this issue.
Comment #16
yched commentedWorks for me. Thanks !
Comment #17
dries commentedCommitted to CVS HEAD. Thanks.