Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
field system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
2 Oct 2019 at 09:57 UTC
Updated:
4 Jun 2020 at 11:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
taran2lComment #3
avpadernoComment #4
hardik_patel_12 commentedComment #5
hardik_patel_12 commentedComment #6
naresh_bavaskar@Taran2L
yes, I also find that field_test_field_attach_delete_bundle() is not needed. thanks
Comment #7
avpadernoComment #8
taran2lCheck against the baseline in #3081386-70: [META] Fully support PHP 7.4 in Drupal 7:
Comment #9
mcdruid commentedThis one seems a bit less trivial than some of the tiny syntax tweaks; we obviously want to make sure we're not just removing code from the tests because there's a bug in it which PHP 7.4 is "sensitive" about if that code is otherwise valid / valuable.
However, in this case it does look like perhaps this function never really did anything and is largely copy-pasta - hence the check against
$bundle_oldwhich isn't initialized, as the IS mentions.AFAICS this code came from #443422-15: 'per field' storage engine and has changed very little since.
Using Xdebug to step through the hook being invoked e.g. by
\EntityFieldQueryTestCase, it looks like$field = field_info_field($field_name);is always returning null - hence the Notice - and the rest of the code effectively does nothing.The reason we're always getting null is that the
$instancesarray is not keyed by$field_name- it comes fromfield_read_instances()(withinfield_attach_delete_bundle()) and is keyed numerically.I _think_ changing the code like this might make it more "correct":
However, the only tests in core which actually seem to use this alternative storage backend are:
\FieldAttachStorageTestCase::testFieldAttachSaveLoadDifferentStorage\FieldAttachStorageTestCase::testFieldStorageDetailsAlterIt looks like these tests do result in
hook_field_attach_delete_bundle()being invoked, but again it looks likefield_test_field_attach_delete_bundle()is redundant, as none of the instances that are passed to it usefield_test_storage.However the hook does get invoked when other tests call
field_attach_delete_bundle()and causes this Notice.So question is should we fix it (it won't actually do anything in core's tests at least, and has never worked properly anyway), or just remove it?
In general less code is good, so yes I think I agree with nuking this from orbit.
Out of interest, let's see if my "fixed" version above passes tests, but even if it does I don't think it's really achieving much; we're not increasing test coverage within core, and if
field_test_storagehas been used in contrib tests (seems unlikely), this hook has never worked so it's not likely any assertions have been based on it.Comment #10
mcdruid commentedOk, interesting so tests pass with the patched version... although that only means that we've avoided the Notice because we're no longer trying to access array elements on a null.
Anyone else have any thoughts about whether there's any value in fixing this rather than blowing it away?
Comment #11
mcdruid commentedI would have no problem with removing this hook per #2 but if we want to address the remaining bugs around bundle / instance deletion (e.g. #1340390: "Deleted" but "inactive" fields and instances cannot be removed during cron cleanup (e.g. for uninstalled entities). and #2337139: Fields with instances attached to unknown entities are deleted on cron run) later, we may want to use / expand on these tests.
So I'm going to vote to do the fix instead, per #9
Either works in terms of avoiding the PHP 7.4 Notice.
Comment #12
avpadernoFixing seems the correct action to do to me too. It's a bug the changes in PHP 7.4 made evident.
Comment #13
fabianx commentedRTBM, approved - let's get this in. I agree that #9 is better.
Thanks, all!
Comment #14
mcdruid commentedComment #16
mcdruid commentedThanks everyone!