Upon creating content with a content type that has an image field set to 'unlimited' for 'number of values' - that node will only allow 2 attached images (using the Upload' button) before breaking.
Initially upon creating a node the 'Add a new file' form disappears once 2 images are added via 'Upload'. Then, after reloading (saving) the page the 'Add a new flie' returns. However, attaching a new image is still not possible as the image disappears as soon as it has been uploaded with the 'Upload' button.
Finally, (don't know if this helps) when editing a node with 2 images already attached, if you just click the 'Upload' button without browsing and attaching anything - image number 2 disappears. Seems to be an array incrementing issue somewhere?
Comment | File | Size | Author |
---|---|---|---|
#57 | 913846_5.patch | 4.14 KB | tstoeckler |
#55 | 913846_test_only.patch | 1.78 KB | grendzy |
#55 | 913846_4.patch | 3.58 KB | grendzy |
#45 | 913846_3.patch | 2.54 KB | grendzy |
#45 | 913846.patch-NON-WORKING-TEST.txt | 1.62 KB | grendzy |
Comments
Comment #1
raydale CreditAttribution: raydale commentedComment #2
bojanz CreditAttribution: bojanz commentedI can confirm this, drove me nuts on a test site back in CPH.
Good reminder to try and debug it tomorrow.
Comment #3
webchickThis needs tests.
Curious, does this happen with any multivalue field, or is it specific to images?
Comment #4
bleen CreditAttribution: bleen commenteda) I have confirmed this bug
b) This seems to only effect images & files. I also tried a text field, decimal field, long text and a long text w/ summary fields and they each worked fine
Comment #5
bleen CreditAttribution: bleen commentedSo I've started narrowing this down a bit...
in file_ajax_upload() (file.module:245) There is the following:
The dsm($settings) outputs this after the first upload:
but after the second upload:
Notice the two remove buttons, but missing "upload" button... getting close
Comment #6
catchMoving to file module.
Comment #7
bleen CreditAttribution: bleen commentedbleen == stuck
Comment #8
chia CreditAttribution: chia commentedsubscribe
Comment #9
sebyoga CreditAttribution: sebyoga commentedHello,
I have just made out a will with the version drupal-alpha7, and the bug seems to have been corrected.
Best regards,
Sebastien
Comment #10
rfay@sebyoga, you don't have to make out your will just because of one bug! And I definitely don't recommend using drupal as a pattern :-) There's no need to take this quite so seriously.
Comment #11
petiar CreditAttribution: petiar commentedConfirming this bug, subscribing.
Comment #12
hexblot CreditAttribution: hexblot commentedConfirming this bug, and adding some more symptoms:
* Once you upload one image, if you remove it (while having the upload button visible), the upload button stops working (in the sense that though data is sent to the server, along with image data, the display is not refreshed to reflect this. Saving the node at this point shows that the image was uploaded normally).
* Once you upload both images, and try to remove one:
* if the image is the first in the list, both images disappear
* if the image is the second in the list, it gets removed, but breaks the remove button for the other image.
Comment #13
raydale CreditAttribution: raydale commentedI have seen the same issues Hexblot and have submitted another bug report regarding that particular one here: http://drupal.org/node/913472
Comment #14
aaron CreditAttribution: aaron commentedsubscribe
Comment #15
bleen CreditAttribution: bleen commentedyet another symptom ....
if you accidentally hit the "upload" button before you actually choose a file, then the browse button stops working untill/unless you reload the page... so to sum up:
Comment #16
sebyoga CreditAttribution: sebyoga commentedOk, i reproduce this Bug, subscribe !
I have found a another bug, When you preview a add / edit node, and after you click on button "upload" on the input file upload, the page is reloaded, and the node is not save.
Comment #17
rfayOK, so nearly everything about #ajax is broken after the commit of #756762: AJAX should follow same rules for whether to call drupal_rebuild_form() as non-AJAX submissions. That may very well be this as well.
Comment #18
rfayCould somebody do a git bisect and find out what commit broke this?
Comment #19
rfayAnd just for grins... Please try the patch in #756762-93: AJAX should follow same rules for whether to call drupal_rebuild_form() as non-AJAX submissions and see if it fixes this.
Comment #20
reglogge CreditAttribution: reglogge commentedRe #19: No, it doesn't fix the bug :-(
Comment #21
rfaygit bisect to the rescue.
This regression happened in #763376-111: Not validated form values appear in $form_state
I thought the problem will be that field_ui uses #limit_validation_errors = array('xxx'), which changed significantly in that issue. But a quick fiddle didn't do it for me.
Comment #22
tim.plunkettI couldn't pin anything down, but I think part of this stems from the code in file.module at line 597-598:
That dovetails with the discovery of #21.
For example, commenting out the form_set_value 'fixes' problem #2 (removing first image removes both). But the UI gets messed up. I'm guessing it's related to form_set_value wrongly overwriting
$element['#parents']
.Comment #23
effulgentsia CreditAttribution: effulgentsia commented@webchick: Re #3: I just saw this issue, so not sure if it's only reproducible under AJAX, but if so, then #789186: Improve drupalPostAJAX() to be used more easily, leading to better AJAX test coverage will facilitate writing a test for this.
Comment #24
Bevan CreditAttribution: Bevan commentedSomething in the attached patch fixes the issue. I don't know what, but will continue "bisecting" the patch.
The attached patch is the reverse diff of changes to
form.inc
andfile.module
in commit #412920. That is the commit relating to #763376-111: Not validated form values appear in $form_state, which is where rfay found the bug was introduced.Comment #25
Bevan CreditAttribution: Bevan commentedI whittled it down to this new section that introduces the bug, thus the attached patch fixes this specific bug. However simply removing this code will of course probably introduce new bugs. I'm continuing to bisect this line-by-line and get into the nitty gritty.
Comment #26
Bevan CreditAttribution: Bevan commentedNow that I have looked through this a little closer, it appears that the
#limit_validation_errors
value for file field elements is causing this error. If it is simply not set infile_managed_file_process()
(as per attached patch), the problem goes away, however other bugs arise. E.g. An error message is not displayed if the file is not of the correct type.I'm not familiar enough with Drupal 7 forms API in order to understand how to fix this properly, but will work on a fix with some direction and guidance.
Comment #27
drifter CreditAttribution: drifter commentedSet to needs review for the testbots to run on the patches.
Comment #28
Bevan CreditAttribution: Bevan commentedThere are known bugs with that patch, and there are no tests for this bug, so test results are meaningless.
Comment #29
kenuck CreditAttribution: kenuck commentedconfirmed bug
if you comment out in file.module :
#limit_validation_errors' => array($element['#parents']),
the issue goes away. But no idea what what new bugs it will bring.
Comment #30
grendzy CreditAttribution: grendzy commentedSee also #675414: Use #limit_validation_errors on File upload and removal
Comment #31
grendzy CreditAttribution: grendzy commented#limit_validation_errors also removes the unvalidated stuff from $form_state['values'].
By setting this key to $element['#parents'], all the other file widgets get removed from form_state. However, file_field_widget_form() needs this data to rebuild the form.
This patch uses array_slice to widen the scope a bit.
Note that the value of #limit_validation_errors is sort of like the coordinates within the $form array - so array('field_image', 'und', 0) translates to $form['field_image']['und'][0].
Comment #32
catchWe could use a test for this. Also the contents of #31 should be massaged into a code comment for the patch.
Comment #33
grendzy CreditAttribution: grendzy commentedI agree about the tests - I don't think this specific issue is likely to regress, but it's mildly concerning that we have no coverage for multi-file uploads.
I'm looking into tests now - but I'm not yet sure if drupalPostAJAX() will suffice because there are javascript behaviors bound to the upload button.
Comment #34
rfayThis issue is what #789186: Improve drupalPostAJAX() to be used more easily, leading to better AJAX test coverage was born for. (And what it was finally committed for). I'm sure hoping we can get a test that's (almost) real.
Comment #38
grendzy CreditAttribution: grendzy commentedHere's the patch with the #limit_validation_errors tags grouped together, with a comment.
While working on this, I've also found more bugs in the remove button. Try this with a file field:
My intuition though is the remove bugs are probably a separate issue.
Regarding the tests I'd be happy for some pointers - drupalPostAJAX is gobbledygook to me.
Comment #39
Shawn DeArmond CreditAttribution: Shawn DeArmond commentedOkay, applied and tested #38.
Using #15 as a guide, here are my results:
Here's some more info on the "more bugs" described in #38:
For the record, I'm testing this using Firefox 3.6.10 on Mac OS X 10.6
Comment #40
Shawn DeArmond CreditAttribution: Shawn DeArmond commentedSo, I'd say it "needs work".
Comment #41
Bevan CreditAttribution: Bevan commentedLoosely related; #925854: Image fields are not aligned in forms
Comment #42
Bevan CreditAttribution: Bevan commentedI confirmed Shawn's report from comment #39. Summarizing:
This patch fixes this bug, but closer inspection and testing reveals more bugs that could not be seen or tested before. These bugs are all related to the "Remove" button. These additional bugs may or may not be related to this issue and patch.
In addition to Shawn's findings, I also noticed that the "weight" field becomes visible after removing an image or file, as per the attached screenshot.
I also confirmed that the remaining bugs continue to apply to file field widgets, as well as image field widgets.
It may be worth committing the current patch and working out the remaining issues separately?
Comment #43
catchPutting this back to CNR. I think the best thing here would be to add a boilerplate test that verifies this particular fix (if drupalPostAjax() is up to it now, not clear if it is). Commit this patch along with that test. Then open a new issue with tests for the other bugs found and fix those separately.
Comment #44
Bevan CreditAttribution: Bevan commentedWhile this is waiting for more review, can someone offer some starting points for writing the test for this? Would it be implemented in JS or PHP? What type of test would it be?
Comment #45
grendzy CreditAttribution: grendzy commentedWhile working on a test, I found 2 more bugs. First, the $delta calculation is wrong in FileFieldTestCase->uploadNodeFile(). It's just coincidence that it happens to work for a delta of zero or one, but breaks if you try to add 2 or more files.
Second, we don't need to set the encoding, this is done automatically in form.inc.
The test doesn't work, but I'll attach it as a separate patch so folks can see what we're up against.
Comment #46
grendzy CreditAttribution: grendzy commentedI've confirmed the remove bugs are unrelated, and caused by #740834: Form elements cannot be rendered without form_builder()
The spin-off issues is #926016: Several bugs when trying to remove files from a multivalued file/image field
Comment #47
Bevan CreditAttribution: Bevan commentedIs the test incomplete? Or just doesn't pass yet?
Comment #48
grendzy CreditAttribution: grendzy commentedBevan: drupalPostAJAX() is an enigma - it's possible I'm using it wrong, or perhaps drupalPostAJAX() has limitations that prevent it from working on file fields. This has never been done before so there are no docs or examples. This issue may have to go in without a test.
Though I believe the patch to the file module is correct.
Comment #49
Dries CreditAttribution: Dries commentedI'm on the fence about this bug being critical as it only affects a small subset of users. It is certainly a major bug but it could be fixed in, say, Drupal 7.1. I'm not changing the priority yet -- gotta think about it some more.
Comment #50
tim.plunkettWould this be considered a regression? It wasn't broken in FileField/ImageField, now it's broken in it's replacement?
Also, I would consider "I want more than 2 files/images" to be an important use case.
Comment #51
rfay@tim.plunkett: This is a regression that happened just since #763376-111: Not validated form values appear in $form_state, if I'm not mistaken. I think we just need to get the #limit_validation_errors correct, and it will be fine. Either that, or there's a problem with the implementation of #763376. But I think it's just that that issue didn't get the #lmit_validation_errors fixed properly in this case.
@Dries: I think you might be right that this is not critical. Unless of course there's a problem remaining in the actual FAPI implementation that's causing this. So I would be completely OK with downgrading this as long as @effulgentsia said "Oh, it's just #limit_validation_errors is wrong", instead of saying "Ooops."
Comment #52
grendzy CreditAttribution: grendzy commentedCorrect, this is a regression - it works in 7.0-alpha6.
Dries: I can't agree this affects a small subset - especially considering file is the replacement for upload.module. I would think it affects virtually everyone (certainly this breaks my own site, which is currently on alpha6). Also why would we wait until 7.1 and not fix it during beta?
Comment #53
effulgentsia CreditAttribution: effulgentsia commentedI agree with handling each issue separately (sorry Dries, I know you prefer reviewing fewer larger patches than many small ones, but sometimes it's easier to keep community effort focused on one issue at a time).
From a usability perspective, it is possible to work around this problem. You can upload 2 files, click "Save", re-edit your node, and upload 2 more, and keep doing that until you've uploaded all the files you want. So maybe that makes this not critical. But, I'm still leaning towards this being critical. It's such an obvious bug (in the sense that lots of users will encounter it) related to a pretty fundamental operation of a CMS (attaching files to content), that Drupal will seem pretty shoddy if released with this broken.
Furthermore, #38 is a simple and correct fix for the bug. Yes, file.module is currently setting #limit_validation_errors incorrectly, and is therefore, unable to have access to values it needs, because those values haven't been validated, and #38 fixes that bug by setting #limit_validation_errors to encompass all the data that the form processing for this form relies on. Given a choice between downgrading priority and committing a fix without tests, I would vote for committing #38 as-is.
But we should be able to add tests to this. Apologies if the lack of drupalPostAJAX() documentation has slowed that down. I'll work on getting that documented. However, this particular issue doesn't require it. The bug happens if you disable JS too, and #38 fixes it. So it should be possible to test this purely using drupalPost(), emulating the steps you take in a browser that has JS disabled. Any takers on that? Sorry, I'd offer to do it, but I have some other issues I'm trying to help out on before being unavailable for a couple weeks again.
Comment #54
Bevan CreditAttribution: Bevan commentedI expect releasing D7 with this bug would attract a lot of criticism. I also think this is a critical bug (not "major"), and that it probably affects a large set of D7 users, likely more than half. With patch from #38 or #45 committed, think this can be lowered to major status while a non-ajax test is written and contributed. However in order to keep the bug from recurring again, I don't think the bug-fix should be accepted without the corresponding test. The issue we split off into #926016: Several bugs when trying to remove files from a multivalued file/image field is perhaps not "critical", but "major".
This does not work for me neither with nor without javascript, on latest head with the default install profile and one configuration change to make the Article->Image field take "Unlimited" values, instead of just "1" value.
Thanks effulgentsia for highlighting that the test can simply use drupalPost() and not drupalPostAJAX to test this.
I think this would be RTBC if it had a working test that fails without the #limit_validation_errors patch, and passes with it.
Comment #55
grendzy CreditAttribution: grendzy commentedGood point about the no-js testing route, thanks effulgentsia!
The first patch is the test only - it's expected to fail.
The second file is the complete patch.
Comment #56
Bevan CreditAttribution: Bevan commentedLooks good!
FYI, another issue that is not related, has caught me out a few times while testing this. It is related to using the "Enter" key to save a node form with files on it: #927176: "Enter" key removes file instead of saving node
Comment #57
tstoecklerIs there any reason we can't set #limit_validation_errors inline like it was before? Patch attached.
Leaving at RTBC, because if there is reasoning against my patch, #55 is RTBC.
Comment #58
grendzy CreditAttribution: grendzy commentedSorry, I don't like #57 because the comment has to be repeated. But I suppose a maintainer can decide which format is preferred.
Comment #59
webchickGreat work, folks!
I went with #55 due to the double comment issue.
Committed to HEAD.