Closed (works as designed)
Project:
Drupal core
Version:
7.x-dev
Component:
forms system
Priority:
Normal
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
24 Feb 2009 at 18:55 UTC
Updated:
18 Jan 2012 at 01:55 UTC
Jump to comment: Most recent file
Comments
Comment #1
dwwActually, I can only reproduce this bug if drupalorg.module is enabled. Moving this to the right queue. Also, this is a regression from the d.o upgrade -- tagging appropriately.
Comment #2
dwwTurns out this is a core bug. Attached is a small module, "twostepnode", that implements a trivial two-step node form (title on page 1, body and everything else on page 2) which exhibits the same bug. To reproduce:
chx promised that if I wrote and posted such a module for the test case, that he'd fix the bug. ;)
Comment #3
chx commentedComment #4
dwwforgive me, webchick, for i have sinned. ;)
Comment #5
chx commentedOn validate, the node form submit handler does not run, form_state[node] is not populated and the taxonomy gets lost. title stays only because the module reads from form_state[storage]. We might need to move form_state[node] to form_state[storage][node].
Comment #6
chx commentedComment #7
dwwThe first hunk in there (the only one that matters) applies to D6, and indeed fixes the bug, both via twostepnode.module and via project_release.module + cvs.module. It makes sense why this now works -- since we don't rebuild the form on a validation error, we don't destroy $form_state['node'] and we save the values. However, I won't pretend like I understand every far-flung corner of FAPI well enough to know if there are going to be places that are broken if forms don't rebuild on validation errors. This still needs more review and testing.
Comment #8
dwwLest anyone freak out about the patch "failing to apply", here's a reroll with the actual code change and a reasonable patch name.
Comment #9
katbailey commentedTested this out on the Quick Tabs admin form, adding elements via ahah, failing validation - everything worked as it should.
Comment #10
chx commentedBot, what do you think?
Comment #12
chx commentedThe full monty: the fix and dww's module pimped out with hook_perm and access and turned into a test module and added a test. I checked, without the form.inc fix we get 17 passes and 1 fail, with the test we get 18 passes. The only question, is this a node test or a form.inc test ? I voted on node...
Comment #13
eaton commentedAs per chx's request I'll be taking a closer look at this, hopefully tomorrow. In the meantime, an attachment here captures some useful data.
Comment #14
chx commentedSome observations. Your form can either be cached or you are building it based on form_state. If it's cached, the patch does not change anything if I am not mistaken (Eaton, please reassure me -- I am very wary of this patch). If you are building then before the patch you needed to re-build once the form for the submit handler. Now you need to be able to build N times because of validation errors. Should you deplete some resource (like some remote API call quota) then this patch will cause failure but then why you are not caching your form? I do not feel a tremendous change going from 2 to N.
Comment #15
webchickSubscribe. Will take a look at this later. Eaton, could you answer chx's question?
Comment #16
chx commentedWe discussed this with Eaton and I am marking this as RTBC as noone reviews it but there is a nice and big test.
Comment #17
webchickOn a very cursory overview (i'd still like someone who is not chx to give this a thorough technical review), there are some minor things:
* TwoStepNodeTestCase missing PHPDoc
* all testXX functions missing PHPDoc
* + * Implementation of hook_perm. and + * Implementation of hook_access. are missing parentheses.
Comment #18
chx commentedAdded doxygen for function testTwoStepNode and fixed the doxygen for hook_perm and access (which i wrote. the rest is dww's and those do not need fixing.)
Comment #19
chx commentedThe class was not! As a penitence I have written a small novel about it.
Comment #21
chx commentedD'oh, new files left out.
Comment #22
webchickStill needs review. Peter said he would look tomorrow.
Comment #23
chx commentedThat was another patch. Noone will look at this. There is a test that should be enough.
Comment #24
pwolanin commentedIt was this patch - I'll give it another look. I did look at the patch once before based on dww's comments re: the bug on d.o
Comment #25
dwwfwiw:
This is the only actual change to core:
Basically, we do not completely rebuild the form from scratch if there are validation errors. The reason rebuilding the form from scratch on validation errors is a problem is that the pseudo $node object passed in to node forms ends up being lost during the rebuild, and that's why multi-page node forms break. Myself, chx, eaton, and merlinofchaos have all considered this, tried to break it or find things this would break, and we all failed. The patch is still passing all core tests, further evidence that the above is a safe change to FAPI.
The rest of this patch is a test to ensure that the above change fixes the actual bug. 90% of the code for the test is the twostepnode.module which I wrote. So, I'm not really qualified to RTBC it, but yes, that code is great. ;)
I'm happy for others to consider the above change to FAPI, but I don't think you're going to do much better than chx, eaton, merlinofchaos and myself for people who know about the internals of FAPI...
Comment #26
webchickThen could you guys please post that to the issue? There are no replies from merlinofchaos, and Eaton's only reply is "I'll look at this later." The last reply from you was "here's a module to reproduce the problem." It makes it appear as though chx is the only one who has reviewed the patch, and I do not feel comfortable committing any patch to form.inc, regardless of how many characters it is, with only one set of eyes on it.
Comment #27
webchickAlso, could you clarify whether the patch you've all agreed to is the latest one or the one from #8?
Edit Nevermind, I see what you're saying. The one-liner fix is the same, the test is different.
Comment #28
damien tournoud commentedThe change looks reasonable, however, the big comment on top of the rebuild condition has *not* been updated. It should capture what dww described in #25.
Comment #29
alynner commentedSubscribing - I would like to see this fix in Drupal 6
Comment #30
eaton commentedThe patch from #25 no longer applies, and -- even more interesting -- the test now runs properly without the changed line of code.
It appears that #322344 may have changed the code already, adding a check for form_get_errors(). Can anyone else confirm?
Comment #31
a9xbqqabtqa6m commentedSubscribing - I would like to see this fix in D6, as well.
Comment #32
gábor hojtsy@chx says this solves the form validation problem we have at #428744: Make the main page content a real block.
@eaton: I tried to find this directly and indirectly in your mentioned patch at #322344: (notice) Form improvements from Views, but via just textual patch review, I did not find it. It could still very well be there.
Comment #33
gábor hojtsy@chx suggested me to roll this change into my patch at #428644: Problem in email system, but when looking at current code (versus the patch above), I see this change seems to have been already applied:
vs. the patch particle mentioned above by dww:
Looks like the current code has even more conditions then this issue suggested originally. Also, this did not solve my problem there.
Comment #34
rtsh commentedHi,
Has anyone any tips for rolling this back to D6, as we'd like to see it fixed there. I can offer a bounty if someone is prepared to do this.
Thanks
Comment #35
baldwinlouie commentedsubscribing
Comment #36
Jeroen_005 commented#12: twostepnode_test.patch queued for re-testing.
Comment #37
barnettech commentedIs this queued for automated testing, or do you guys need someone to test this? If you outline what exactly needs to be tested and you just need someone besides yourself to make it RTBC post the instructions here and I can test this for you. I'm an Architect looking to get more involved but just need a nudge.
Thanks,
Barnettech
Comment #38
barnettech commentedI recreated the sample module in Drupal 8 to test for this bug in comment #2 above (http://drupal.org/node/382634#comment-1306916), I'll post my code when I have a chance. In Drupal 8 I was not able to reproduce the bug. I enter the title, then hit next in the multistep form, then via cck I had added a multi select field. I choose 2 items in the multi select which leaving the required body blank. I get the validation error but do not loose the title or the multi select choices I entered. So this does not seem to be a bug in Drupal 8.
I'll post my code soon and will have a fellow Boston Drupal Meetup member review my work next week.
Comment #39
barnettech commentedAttached is the drupal 8 version of the module from comment #2 above which was made to demonstrate the problem in this ticket. You'll see that the problem no longer exists in drupal 8 (which at this point is almost identical to drupal 7). At the Boston Coding Initiative on Thursday led by bryanhirsch and webchick I'll verify I can close this.
Comment #40
ronaldmulero commentedI can verify that this bug seems fixed in Drupal 8 when tested using barnettech's Drupal 8 version of the twostepnode module.
Creating title, clicking on "Next", selecting 2 items in multiselect but leaving body field blank, then clicking on either "Save" or "Preview" presents the validation error but the title and the multiselect choices remain in the form.
Comment #41
xjmThanks for the testing @ronaldmulero. So if I'm understanding correctly, the bug does not exist in Drupal 8 nor Drupal 7?
If so, we can close this now.
Comment #42
barnettech commentedYes that is correct. If you load the module that I updated in step #39 you'll see in Drupal 8 this is no longer a problem. In our Boston Meetups we're taking on Core bugs and were ordered to just test in Drupal 8, which is almost identical to Drupal 7 at this early stage.
My guess is the module I updated in step #39 is loadable in Drupal 7 as well but just change the .info file to list it as a Drupal 7 module rather than a drupal 8 module.
So the bug no longer exists in these later versons of Drupal. @ronaldmulero helped me test this to confirm it's all set.