I have a article with attachments and when this article is displaying in short form (i.e. when ) i get meny of this errors:
Notice: Undefined offset: 35 w file_field_prepare_view() (linia 201 z /home/esperant/domains/esperanto.pl/public_html/d7/modules/file/file.field.inc).
Warning: Invalid argument supplied for foreach() w file_field_prepare_view() (linia 201 z /home/esperant/domains/esperanto.pl/public_html/d7/modules/file/file.field.inc).
When I remove the attachments the warning disappears.
Comment | File | Size | Author |
---|---|---|---|
#22 | tf-1169426-22.patch | 6.04 KB | plach |
#22 | tf-1169426-22-test.patch | 2.86 KB | plach |
#17 | tf-1169426-17.patch | 2.74 KB | fietserwin |
#7 | tf-1169426-7.patch | 3.04 KB | plach |
Comments
Comment #1
Luna Vulpo CreditAttribution: Luna Vulpo commentedI forgot write. This problem shows up after upgrading to 7.2
Comment #2
calculus CreditAttribution: calculus commentedSubscribing
Comment #3
webchickWe need tests for this condition, because they should've caught this.
By attachments, do you mean filefield uploads?
Comment #4
Luna Vulpo CreditAttribution: Luna Vulpo commentedYes. I add field to standard content type "article". I set for this field "field type is file"
I comment the content of this function and this warning disappears but is is not clean solution so i submit bug report.
I thing that problem is elsewhere because is this function looks same as in D7.0
Comment #5
pmelab CreditAttribution: pmelab commentedGot the same issue. Only happens if a file field is left empty and the node is displayed in a list. Looks like the $items array is not populated with all entity-ids occuring in $entities.
Same problem with taxonomy terms.
Comment #6
olafveerman CreditAttribution: olafveerman commentedSame issue here, but in my case it also happens when I have nodes of different languages in the list even if all filefields have a file.
Comment #7
plachThe attached patch should fix the issue, tests are still missing.
Comment #8
webchickThanks for getting on this so quickly, plach! :D
Comment #9
plachI should stop fixing core issues at 3:00 AM, see what happened the last time :(
Comment #10
ubersuts CreditAttribution: ubersuts commentedHi, when I try a dry run of the patch, I get this:
patch -p1 --dry-run < ./tf-1169426-7.patch
patching file modules/field/field.attach.inc
Hunk #1 FAILED at 303.
Hunk #2 FAILED at 312.
Hunk #3 FAILED at 329.
Hunk #4 FAILED at 347.
any ideas what I might be doing wrong?
Comment #11
plachBe sure to checkout the latest code from the 7.x branch, this applies cleanly to 7.2 however.
Comment #12
yli_ektor CreditAttribution: yli_ektor commented#7: tf-1169426-7.patch queued for re-testing.
Comment #13
rodrigoaguilerasuscribe
Comment #14
lklimek CreditAttribution: lklimek commentedPatch #7 seems to fix the issue (or at least remove error messages ;) ).
Comment #15
oerjann CreditAttribution: oerjann commentedPatch #7 removed the error messages for me to :)
Comment #16
fietserwinPatch #7 solves #1164230: Invalid argument supplied for foreach() in taxonomy_field_formatter_prepare_view() line 1429 of taxonomy.module for me! Marking that one as duplicate.
Comment #17
fietserwinPerhaps using the $items from the foreach is more clear (although the PHP manual states that foreach operates on a copy, the old version seems to work anyway):
Comment #18
yareckon CreditAttribution: yareckon commentedsubscribe
Comment #19
Carlos Miranda Levy CreditAttribution: Carlos Miranda Levy commentedPatch applied properly and errors are gone on 7.2 multisite site
Comment #20
webchickI'd like to make sure this is part of 7.3.
Any takers on writing that test?
Comment #21
plachI'll do
Comment #22
plachHere are tests. The test-only patch is supposed to fail to show that tests capture the bug.
Comment #24
webchickStop that, bot. :)
Comment #25
darq88 CreditAttribution: darq88 commentedeee...how to install this patch?
Comment #26
fietserwintake the most recent patch (not the test only one) and remove the test part out of it before applying
Comment #27
darq88 CreditAttribution: darq88 commentedsorry, I'm new to drupal could you explain it to me step by step?
thx for your replay
Comment #28
fietserwinTry http://drupal.org/node/707484
Comment #29
g4b0 CreditAttribution: g4b0 commented#22 worked for me!
Comment #30
isaac.el.cec@gmail.com CreditAttribution: isaac.el.cec@gmail.com commented#22: tf-1169426-22.patch queued for re-testing.
Comment #31
eduardo barros CreditAttribution: eduardo barros commented#7: tf-1169426-7.patch queued for re-testing.
Comment #32
aspilicious CreditAttribution: aspilicious commentedSub
Comment #33
jviitamaki CreditAttribution: jviitamaki commentedSub
Comment #34
plachOk, it seems the patch fixes the issue: a feedback from @yched and @sun would be welcome...
Comment #35
sunI'm not really sure whether we also need to stack all entities by language. For monolingual sites, this change makes no difference. But on multilingual sites, $grouped_entities will contain {fields} x {languages} "copies" of each entity. Whereas it looks like we.......
well, scratch that - the overall processing logic already exists. Looks like _field_invoke_multiple() could use some @chx magic and @sun clean-up in a follow-up issue.
Is there a reason for allowing the callbacks to change $items in $grouped_items[$field_id] by reference?
Powered by Dreditor.
Comment #36
plach@sun:
If I'm not mistaken objects are always passed by reference, so what get copied are object references not object data structures.
Well, this is only a readability improvement: the old code already lets items be passed as reference, see for instance: http://api.drupal.org/api/drupal/modules--field--field.api.php/function/....
Comment #37
sunWhile that is true, the
foreach ($items[$id] as $delta => $item) {
generates a copy of &$items[$id][$delta] as $item. Only the results of the callback are put back to the &$items passed by reference, but the callback only gets the copy in $item.I'd suggest to revert that change to the foreach for now. Deciding on whether field callbacks should be allowed to manipulate $items by reference looks like a different question to me that should be discussed in a separate issue.
Comment #38
plachI cannot parse your latest comment: the current
_field_invoke_multiple()
code passes$grouped_items[$field_id][$langcode]
as the$items
parameter ofhook_field_X()
(multiple) implementations. Implementing hooks may decide to get a reference or a copy depending on their signature.Do you mean that the current code always passes a reference and so hooks altering for their private reasons the
$items
array may see their changes unintentionally propagated?Comment #39
sunah, ok, now I get it -- you also replaced $grouped_items[$field_id][$langcode] with $items in the arguments passed to the field callback.
Alright, makes sense.
Powered by Dreditor.
Comment #40
Levure CreditAttribution: Levure commentedsubscribe
Comment #41
henwu CreditAttribution: henwu commentedsubscribe
Comment #42
snupy CreditAttribution: snupy commentedsubscribe
Comment #43
auris CreditAttribution: auris commentedsubscribe
Comment #44
mordonez CreditAttribution: mordonez commentedsubscribe
Comment #45
auris CreditAttribution: auris commentedUsing view's frontpage, you don't get this warnings.
Comment #46
webchickAwesome work! Thanks folks!!
Committed to 8.x and 7.x.
Comment #47
Levure CreditAttribution: Levure commentedHello !
I have a production site impacted by this issue.
Is the patch [tf-1169426-22.patch] reliable ?
Do we have to manually apply that patch, or is there a new core release planned soon ?
Many thanks in advance for your reply ! :-)
Comment #48
plachThe patch in #22 got committed: a development snapshot is coming in 4 hours. If I understood the current plans correctly, the next stable release should be available by the end of June.
Everyone here is encouraged to test the patch by manually applying it or downloading the development snapshot, because the code in it will be part of D7.3. We have more than one week to fix possible side effects and ensure D7.3 behaves well, let's make this happen ;)
Comment #49
eduardo barros CreditAttribution: eduardo barros commentedpatch in #22 is working for me.
Comment #50
texis CreditAttribution: texis commentedpatch in #22 is working for me too :-)
Comment #51
Axl CreditAttribution: Axl commentedSub
Comment #52
Levure CreditAttribution: Levure commentedFor information, this patch is now included in Drupal 7.4 release.
Thanks to everybody ! :-)
Comment #54
wogelberg CreditAttribution: wogelberg commentedi am running windows and cygwin doesnt work properly for me.
*pulling my hair out and crying*
cant somone upload the patched files instead of the patch.
thanks