When I add a FAPI managed file field to a non-entity form and upload a file when the sites/default/files directory has insufficient permissions to write I get the following message:
Notice: Undefined index: #field_name in file_managed_file_save_upload() (line 638 of /var/www/ae7/modules/file/file.module).
The problem being that on non-entity forms #field_name is not set.
This affects things like the media module, along with these other issues:
#1373046: Zen | Notice: Undefined index: #field_name in file_managed_file_save_upload() | line 630 file.module
#1218048: Notice: Undefined index: #field_name in file_managed_file_save_upload()
So either the problem is that non-entity form elements should be getting a #field_name, or other modules should not be relying on #field_name being there.
It seems like it should be the former.
I still need to check drupal 8 for the same issue.
Comment | File | Size | Author |
---|---|---|---|
#76 | interdiff-1903010-74-76.txt | 1.04 KB | yogeshmpawar |
#76 | 1903010-76.patch | 3.49 KB | yogeshmpawar |
#74 | reroll_diff_1903010-68_1903010_74.txt | 2.6 KB | yogeshmpawar |
#74 | 1903010-74.patch | 3.49 KB | yogeshmpawar |
#68 | 1903010-68.patch | 3.6 KB | Abhijith S |
Comments
Comment #1
rooby CreditAttribution: rooby commentedComment #2
timbrandin CreditAttribution: timbrandin commentedThis line should not give any errors anyways (modules/file/file.module:637)
Comment #3
buddaI've seen the same issue when playing with Open Atrium 2 and uploading a banner image via the Media module.
Comment #4
buddaChanged the $element index to match the other one used in the same function later on.
Comment #5
buddaComment #6
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedI goto upload a file via the media module
I get the error above and can't upload the file
Notice: Undefined index: #field_name in file_managed_file_save_upload()
The file could not be uploaded.
Upload a new file field is required.
With the patch the error goes away, but I still can't upload the file with:
The file could not be uploaded.
Upload a new file field is required.
Comment #7
Dave ReidThis patch wouldn't affect the ability to upload a file, so the error in #6 is unrelated. #6 actually confirms what this is fixing is fixed.
Comment #10
dcam CreditAttribution: dcam commentedComment #13
dcam CreditAttribution: dcam commentedComment #14
David_Rothstein CreditAttribution: David_Rothstein commentedDid anyone check? Looks like extremely similar code exists in Drupal 8, so I would expect the bug is very likely to exist there too.
Comment #15
jhedstromComment #16
jhedstromNot reroll. Just needs to be verified if this is fixed in D8 or not.
Comment #17
Dave ReidSame fix for Drupal 8, but changing "for the file field !name" to "for the !name field" since we cannot assume this is being used with a file field.
Comment #18
Dave ReidThe same patch for Drupal 7 (marked as DNT).
Comment #19
Dave ReidThis is a blocker for File Entity. We keep getting bug reports about this, anyone able to review the latest versions?
Comment #20
dermarioThe patch in #18 works for me on D7. There is no notice any more.
Comment #21
discipolo CreditAttribution: discipolo commentedthe patch from #18 for D7 works for me too and allows the patch from #2074625: Allow filename (and possibly other attributes) to be edited during upload process on file_entity to work.
Comment #22
jday CreditAttribution: jday commentedTested the patch in #18 and it works, no longer getting the error message
Comment #24
Sebastien VR CreditAttribution: Sebastien VR commentedFixed paths in patch file from #18.
Comment #27
oriol_e9gSame notices detected writing tests in Drupal 8.
You can see the notice using a managed_file in a theme settings: https://www.drupal.org/node/1862892#comment-11766744
And then the notices go way when apply the patch in #17: https://www.drupal.org/node/1862892#comment-11766843
For me patch in #17 is RTBC
Comment #28
amit.drupal CreditAttribution: amit.drupal as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedTested the patch in #18 and it works, no error message found.
Comment #29
catchRe-uploading #17 for testing since it's 18 months old. Didn't review yet.
Comment #30
catchPatch didn't make it.
Comment #32
dermarioRerolled the patch in #17 to apply against the latest 8.2.x
Comment #33
dermarioComment #34
catchThanks for the re-roll.
The lack of test changes means we don't have test coverage for this hunk in file_managed_save_upload(), so let's add some here.
Comment #35
oriol_e9gComment #36
oriol_e9gAnd this should pas.
Comment #38
amit.drupal CreditAttribution: amit.drupal as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commented@oriol_e9g #36 looking nice.
Please see notice-fix-and-test-1903010-38.png .
Comment #39
catchThat's much better, thanks!
Missing period on the end of the comment but that can be fixed on commit. Moving back to RTBC.
Comment #40
oriol_e9gComment #41
xjmWe no longer support
!placeholder
so we should not use it with the logger either.https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Rend...
https://www.drupal.org/node/2575819
https://www.drupal.org/node/2605274
Thanks!
Comment #42
xjmAlso the fact that the patch passed implies to me the test coverage isn't quite complete?
Comment #43
oriol_e9gComment #44
oriol_e9gIf you want, we can test that the notice is generated and saved correctly in the DBLog... but I don't know if it's really necessary for a notice message.
Comment #46
oriol_e9gRandom test fail, attached more compact test.
We can use this patch #46 or #43 if we think that it's not necessari test the notice message.
Comment #48
cebasqueira CreditAttribution: cebasqueira commentedSmall change to become more coherent!
Comment #49
cebasqueira CreditAttribution: cebasqueira commentedComment #51
cebasqueira CreditAttribution: cebasqueira commentedComment #54
kenorb CreditAttribution: kenorb commentedSame problem in 8.3.7, but the patch doesn't apply cleanly for 8.3.x.
Comment #55
jhedstromNeeds a reroll (presumably since arrays are now in bracket syntax). Could somebody also re-upload the test-only patch since that has changed since the last test-only patch?
Comment #56
jofitz CreditAttribution: jofitz at ComputerMinds commentedRe-rolled.
Comment #60
mErilainen CreditAttribution: mErilainen at Wunder commentedThis seems to be in Drupal 8.6.x except for the array syntax change and the new test?
Comment #61
EktaPuri CreditAttribution: EktaPuri commentedI am having same issue with Drupal 8.6.10 and the #56 patch is failing, I am new to Drupal and not using git
error i receive
Hunk #1 FAILED at 2.
Hunk #2 FAILED at 10.
patch unexpectedly ends in middle of line
Hunk #3 FAILED at 148.
any suggestions plz
Comment #64
raman.b CreditAttribution: raman.b at OpenSense Labs commentedRe-rolling for the current dev branch
Comment #65
raman.b CreditAttribution: raman.b at OpenSense Labs commentedResolving deprecation notices
Comment #68
Abhijith S CreditAttribution: Abhijith S as a volunteer and at Zyxware Technologies commentedFixed the CS issues in the patch #65
Comment #69
buddaWow, 7 years since I wrote the first patch for this in D7 and the issue still isn't closed!
Comment #71
Kristen PolThanks for the updated patch. We are using patch #68 and it fixed the fatal
file_managed_file_save_upload
error for a site with Drupal 9.2.11.The patch applies with offsets to 9.3, 9.4, and 10.
Comment #72
Kristen PolIt would be good to have specific steps to reproduce so we can test on 9.4 and then get this issue committed :)
Comment #73
Kristen PolLooked at the code and one minor nitpick.
IMO this could be simplified so it's easier to read, e.g.
Might also be nice to include the filename, e.g.
Comment #74
yogeshmpawarAddressed #73 & rerolled the patch against 9.4.x branch.
Comment #76
yogeshmpawarUpdated patch will fix test failures. One thing missed in previous patch.