Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
file.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
7 Feb 2012 at 06:59 UTC
Updated:
19 Dec 2019 at 12:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
audster commentedHave a look here...
http://drupal.org/node/714350
Comment #2
orkutmuratyilmazI had a look there and found nothing useful unfortunately.
That patch already had adapted to the drupal core, as Dries said.
But I'm still experiencing the same error.
Comment #3
audster commentedYou might want to try flushing the cache (again) and then manually deleting the referenced index from your DB.
see http://drupal.org/node/1351506#comment-5428118
I was untangling and indexing error for comment_node_panel (and several other indexing errors)
I worked through this suggestion and it has entirely ended indexing errors on my site..
Let me know...
Comment #4
larsbo commentedI am not sure, but this issue might have something in common with http://drupal.org/node/1463860 which I am struggling with.
Comment #5
berdirThe attached patch fixes the notice for me.
There might be a better way to do it (enforcing that the setting exists), but this at least allows to get rid of the notice.
Comment #6
berdirComment #7
LTech commentedI also got this error on the upgrade from 7.12 -> 7.14.
The patch in #6 took away the error.
Thanks
Comment #8
nor4a commentedI do not like patching the core files.
But seams that sometimes it is just necessary.
Thanks for the patch!
Comment #9
viseser commentedThanks for the patch !!!
Comment #10
droplet commentedComment #11
zerolab commentedAttaching the patch against 8.x-dev.
Comment #12
jherencia commentedBoth patches worked.
Comment #13
webchickIt would be nice to get some tests for this. Any idea how to trigger the error?
Comment #14
najim commentedhad a problem with undefined index patch #6 worked for me, d7.16
Comment #15
chlarkkirby commentedUpdated my installation to 7.19 and i got a problem on line 579, and i tried patch from #6, it worked! :-)
Comment #16
mathankumarc commentedI think issue has been hijacked from 8.x to 7.x :(
Comment #17
berdirYes, this is still needs work for tests for 8.x
Comment #18
kevin morse commented#11: use-not-empty-1430934-11.patch queued for re-testing.
Comment #19
tregismoreira commentedThe patch #6 works perfectly for me (D 7.22). Thanks! :D
Comment #20
damienmckennaRegarding webchick's question of how to trigger it, the error was showing on a D7.22 site when a user clicked the "add another" twice for a text field, i.e. for a total of three values on one text field. How would that be tested?
Comment #21
damienmckennaRerolled. Also changed the logic to get rid of the trinary operator and use intval(empty()) instead.
Comment #22
helmo commentedI've marked #2037549: Notice: Undefined index: display_field in file_field_widget_value() (line 587 of */modules/file/file.field.inc) as a duplicate of this issue.
I've had the same issue in D7.26, the patch from #6 fixed it for me.
Comment #23
danepowell commentedHere's the D7 version of #21, for anyone who needs it.
Comment #24
milesw commentedThanks, #23 eliminates the notices in 7.26.
Comment #25
robert.laszlo commentedApplied this against HEAD, and it no longer applies.
Comment #26
johnish commentedI'm looking in to rerolling the patch and updating the issue summary.
Comment #27
johnish commentedComment #28
johnish commentedRerolled the patch. Uploading for testing.
Comment #29
johnish commentedComment #30
johnish commentedComment #31
johnish commentedComment #32
littledynamo commentedThis bug doesn't appear to exist in D8, or at least I can't reproduce it.
Review carried out:
- Latest dev of D8 (clean install)
- Added a field of type "Text (plain)" to the article content type and set values to "unlimited".
- Add node of type article. There are 3 textfields showing initially.
- Added text to all 3 textfields. Added another textfield with some dummy text. Added a fifth textfield with dummy text and saved the node.
- No error messages.
I then applied the patch in #28 and carried out the above steps - also no errors.
Comment #33
alexpott@littledynamo looking at the code and issue summary this appears to be a file field issue - can someone confirm that we still have the issue in 8.0.x? Thanks.
Comment #34
jsobiecki commentedComment #35
rpayanmAgree with @littledynamo I can't reproduce this issue.
And:
Is impossible clicked the "add another" twice for a text field, because the button become disable until the next text field is add.
Comment #36
zaporylieI also suggest that we should change status of issue to "cannot reproduce". I've tried to reproduce it under D8 and D7 without any success.
Comment #37
jaydub commentedFWIW it seems that was only ever an issue on D7 and that patches in this thread fixed it. However those patches were never committed to D7 and closing the ticket since the problem doesn't/never did appear in D8 would seem to leave D7 w/o a fix.
We encounter this notice in our logs now with the latest version of Drupal 7.32.
Comment #38
jaydub commentedComment #39
pushpinderchauhan commentedPatch for D7.
Comment #40
nachenko commentedPatch from #39 worked like a charm. Thanks!
Comment #41
damienmckennaFYI the patch in #39 is identical to the one from #23.
Comment #42
monaw commentedWhen will this patch be released from dev? Unfortunately I cannot patch our core as I don't have admin privileges. We are running the latest core, 7.38. I'm getting this error on a regular file field.
Comment #43
damienmckenna@monaw: This will be committed once it gets to RTBC and one of the core maintainers commits it. To help it on its way you could try doing a local test of the patch and provide a review, even if you're not able to run it on a production site.
Comment #44
monaw commented@DamienMcKenna: thanks you for your reply! I look forward to the release.
Unfortunately I don't have time to setup a local test of the patch and provide a review, I'm very sorry. I have a crazy deadline coming up and my boss will give me a lot of grief for taking "his" time to do that as we have a rather complicated system and it will take quite awhile to setup a local replicate. Actually the system I'm working on is our "dev" and still I don't have the privilege to patch core. It is very unlikely that the sysadmin will patch core as the copy of Drupal is shared among many other sites at our organization.
Comment #45
das-peter commentedI think #23 / #39 miss to invert the return of
empty().We want
$input['display'] = intval(!empty($field['settings']['display_field']));.We had that already in #6.
Comment #46
monaw commentedOk, I figured out the solution without having to hack core (because I don't have permission to do so)…
The problem was caused by a hidden image field. When I changed the image field to not hidden in the content type settings, then the error went away. But for our application, we don't want to show that field so in my custom module, I set the field's #access to FALSE:
and that worked…field is not shown and there is no error (:
By the way, I'm using Drupal 7.38.
Hope this helps someone else!
Comment #47
cilefen commented@monaw It would be great if you could please provide a review. That is how the issues move toward completion. Is the critique in #45 from @das-peter valid? If so, provide a new patch with the change instead.
Comment #48
SGhosh commentedCould not replicate.
Comment #49
akosipax commentedThis error not only appears for textfield with multiple values. In my case, I have a Price Table field (from commerce_price_table) with unlimited values and when I click "Add another" more than twice, this error starts appearing.
This has been tested in 7.x-dev and the errors disappear. This is simply patch #39 with das-peter's correction in comment #45.
Comment #50
njbarrett commentedI am getting this error when programatically submitting and validating node edit form. e.g.
A form callback with:
field_attach_form($entity_type, $entity, $form, $form_state);The patches in #49 fixes the issue.
If I get some time I will write a test.
Comment #51
malcomio commentedThe patch in #49 would introduce a bug similar to #2593377: "Include file in display" has no effect with media browser widget fields where the display setting would have no effect.
Here's an alternative patch - I haven't been able to reproduce the original issue, though.
Comment #52
njbarrett commentedI believe I have tracked down the cause of the issue.
It seems to be related to image fields, which piggyback on many of the file field functions.
The thing is, in `image_field_info` there is no `'display_field' => 0,` in the settings array, where in `file_field_info` there is.
Now because the image field uses `file_field_widget_settings_form`, which expects `display_field` to be set, we get this notice error.
The patch in #49 is the correct fix for this issue.
Comment #53
njbarrett commentedComment #54
malcomio commentedI think that this still needs more review - as I mentioned in #51, applying the patch from #49 would introduce the following bug:
Steps to reproduce
1. Add a File field to a content type, using the "File" widget, and enable the Display field
2. Create a node with a file in that field, and uncheck "Include file in display"
Expected result
The file is not displayed (to admins or anonymous users)
Actual result
The file is displayed.
Comment #55
njbarrett commentedHey @malcomio
Sorry, I have tested #49 and you are right, it ignores the "Include file in display" checkbox.
I then tested your patch in #51 and confirm it works.
Comment #56
njbarrett commentedI have updated the issue summmary with steps to reproduce.
Comment #57
eangulo commentedPatch from #39 worked for me! Thanks
Comment #58
cilefen commentedCan someone provide a review? That is a required step to get this bug fixed in Drupal core.
Comment #59
g33kg1rl commentedI had this issue happen on a clean install. #51 fixed the issue for me. :)
Comment #60
alesr commentedI did a extensive research on this.
Started with image module where I set the default 'display_field' value. Also tried to add 'display_field' => 0 into $form 'my_image_file_field' where it is expected so it's there before the render kicks in and still the error persisted.
If we look at the original lines in file.field.inc file:
By my means this is bad coding. PHP is quite strict about undefined array indexes and if there's a slight chance 'display_field' is not set, this line will produce a notice.
The outcome of my review is, even if there's an alternative solution to this issue, this line in the if statement should be replaced with:
$input['display'] = !empty($field['settings']['display_field']) ? 0 : 1;In this case, file module doesn't rely that 'display_field' is set. Using empty() function in deep arrays with dynamic indexes makes our lives better.
I suggest we accept the patch in #51 as a confirmed solution.
Comment #61
alesr commentedBump.
Can this issue get some D7 core contributors attention?
Comment #62
elijah lynn#51 Appears to work for the case I was having.
Comment #63
fabianx commentedStraightforward, marking for commit and very probable inclusion in 7.50.
Comment #64
David_Rothstein commentedWhile the patch is certainly harmless, I think we should be careful with these because hiding a PHP notice sometimes hides an actual bug with deeper consequences...
Bottom line, reading through the issue the root cause of the problem is not clear.
Naively, it should not be a problem at all:
$input['display']equal to 1 also, so the error should never occur.The steps to reproduce in the issue summary do work, but require doing this:
If you call drupal_build_form() first, that is going to put all sorts of things in $form_state['values'] that aren't normally there. I don't think it's a documented or supported way to call drupal_form_submit()... normally you would just build $form_state['values'] manually with the values you're actually trying to submit. If you do that I don't think this bug occurs.
The duplicate issue at #2037549: Notice: Undefined index: display_field in file_field_widget_value() (line 587 of */modules/file/file.field.inc) mentions something with the Field Collection module as a way to reproduce, but I wasn't able to figure it out.
So does anyone understand a way to reproduce the problem in the real world? If there is one and it's not due to other code doing something else wrong, I'd be in favor of this issue.
Also, this issue originally got the "Needs tests" tag in #13 but it's not clear why it was later removed. There are no automated tests in the patch, and automated tests would help (among other things) figure out if it's an issue in Drupal 8 also. People said above they couldn't reproduce it in Drupal 8, but I'm not sure any of those same people could reproduce it in Drupal 7 either! The code is very similar in Drupal 8 so I'm not really convinced this is actually a Drupal 7-only bug, if it's a bug at all.
Comment #65
stefan.r commentedComment #66
Anonymous (not verified) commented+1 for the patch in #51.
I'm running into this issue with a site using paragraphs, and I can't open the modal to edit because of it.
My guess is there is an older file field that doesn't have the proper default settings, or some other bug deleted it.
Either way, it's still an error that can happen.
And 51 isn't hiding any php notices, it is correcting poor coding that was assuming
$field['settings']['display_field']will always be set.I think this is good to go back to RTBC
Comment #67
aporie#51 works for me with File field path and File resup
Why not publishing this patch with the next update ?
Comment #68
alesr commented@Aporie because it requires tests. Mentioned in #64.
Comment #69
hkirsman commentedWorked for me. Tx!
Comment #70
polPatch #51 does the job for me as well.
Comment #71
joseph.olstadBumping to 7.61, this didn't make it into 7.60
Comment #72
joseph.olstadComment #73
opgobee commentedPatch #51 worked for me. I encountered the error on uploading an image on the edit form of a node, on Drupal 7.61.
Reading around, the error seems to occur for images as they have no display_field according to https://www.drupal.org/project/drupal/issues/714350 #2 and #9.
The patch that checks the presence of the display_field prior to calling it, appears sensible.
Comment #74
joseph.olstadComment #75
fabianx commentedI have decided to commit this without Tests as hardening of the code instead of a bug report:
- Several people had been able to reproduce it using contrib modules (there is an impact)
- Core itself ran into this problem in Drupal 7.9 and fixed it for the image formatter specifically -> This means every other (contrib) implementation would need to fix it again and again, which is a "red flag" in itself
- If something is empty, it's okay to assume that it's meant to be 0
While there could be bugs hidden by hiding the notice, the probability that they would like that to show is very unlikely (and would be noticed in manual testing) and behavior for already broken code does not change
Therefore => Committing
Only need to check if Drupal 8 needs something similar to harden first
Comment #76
fabianx commentedOkay, in Drupal 8 the code is the same:
However in this case
$element['#display_field']is always set as code before that adds it extra:But because we never use $field['settings'] again in D7 at that point, the fix is good to go as is, e.g. there is no win for us to add the 'display_field' => NULL to the settings over the fix here.
=> Ready to be Committed
Comment #77
fabianx commentedCommitted and pushed to 7.x! Thanks all!
Comment #79
polThanks !
Comment #81
pavel.zheldak commentedStops working with core version 7.69. Updating patch to be applicable for latest core.
Comment #82
alesr commentedIsn't that going to return the same value in integer for both cases?