Given that a Mollom session_id can change across requests (not often, but it can), it makes no sense to try to bind any data onto it and cache it.
Instead, we need to leverage Form API's own form caching. Some background:
- $form_state is already populated in case of a form validation error. In this case, the form is basically rebuilt within the same request, just as if $form_state['rebuild'] would have been set, but re-using the same $form_build_id.
- Due to form caching, Form API reads and writes $form and $form_state to its own cache, bound to the $form_build_id, which can change across requests and definitely changes when a form is explicitly rebuilt (a.k.a. multi-step forms).
- $form_state is not populated in case Form API did not find a matching cache for the form. In this case, we need to assume that we also need to rebuild our form data.
Note that form caching in D6 is buggy, so it is perfectly possible that all of this only applies to D7.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | mollom-HEAD.cache_molllom.10.patch | 20.39 KB | sun |
| #9 | mollom-HEAD.cache_molllom.9.patch | 18.88 KB | sun |
| #7 | mollom-HEAD.cache_molllom.7.patch | 18.89 KB | sun |
| mollom-HEAD.kill-cache.patch | 1.35 KB | sun |
Comments
Comment #1
damien tournoud commentedWe build that external storage for a reason: many forms were broken in D6 and broke horribly when you tried to rebuild them. Example: the comment form.
I really do hope that this is not necessary anymore in Drupal 7 :)
Comment #2
dave reidSeems reasonable that cache_mollom isn't necessary in D7 with all the great improvements you've been driving in sun.
Comment #3
sunExactly. We've taken care of most bugs in D7 already:
http://drupal.org/project/issues/search/drupal?issue_tags=D7%20Form%20AP... :)
Additionally, all forms in D7 need to be aware of form caching due to the new #ajax framework, so we should be safe to do this.
Comment #4
sunuhm, for later reference'n'investigation... note that form caching of $form_state is buggy in D6, but caching of $form is pretty straightforward (almost no changes in D7). Might be worth a try.
Comment #5
damien tournoud commentedDoubtful. The issue is not that the form caching is buggy in D6, it's that some *forms* are broken, and do not like being rebuilt.
Comment #6
sunCore bug for reference:
#648170: Form constructors cannot enable form caching or form rebuilding
Comment #7
sun1250 passes, 0 fails, 0 exceptions
Comment #8
sunThat's the issue I linked to in the previous follow-up. Without this override, the 'cache' flag gets lost in case of a form validation error, and therefore any updated information in $form_state (new Mollom session data) is lost, too.
This is an additional clean-up I sneaked into this patch - already wanted to do this for D6, but ran out of steam there. ;) We may want to consider to backport this, but it's not required.
In short: Whatever result is returned from Mollom servers, it's always stored in $form_state['mollom']['response'].
In the future, we want to check whether we can remove the global $mollom_response variable that we currently use for mollom_data_save(), because $form_state['mollom']['response'] is exactly what we want to store there. The usage of the global variable is caused by having to support e-mails though... a major challenge on its own.
Apparently, this form error message was always displayed next to the "To submit this form, please complete the word verification." message that's already set by textual analysis.
I hope I didn't mixed this up during debugging, so I hope it is correct to remove it. Since the tests pass, it "should" be correct. But anyway, just wanted to point out that this additional form error may have had a (undocumented) reason. So let's try to keep this in mind.
This is a quite interesting edge-case, which doesn't seem to be handled by mollom() yet.
During manual testing, I entered CAPTCHA values that are not compatible with testing keys. Mollom returned a MOLLOM_ERROR response, which did not bubble up. I was asked to re-enter the CAPTCHA all over again. Until I looked into the logs and found the error message.
In a separate issue, we should analyze whether mollom() shouldn't also trigger the fallback behavior in case of a MOLLOM_ERROR, since this error is only handled here for validation of CAPTCHAs with this patch.
I originally wanted to do what the @todo states here, but then reverted that, because I'm not 100% sure whether we also need to account for concurrent form workflows/submissions (of different forms).
I still, really, have no idea at all, why we have to reset our statically cached form information data prior to running _any_ test.
Looking at this again, I guess we want to move it into setUp(), as long as we need it.
Powered by Dreditor.
Comment #9
sun- Double-checked the "CAPTCHA required" form error message manually and removing the additional error message seems to be fine.
- Cleaned up the other two todos from above list.
Comment #10
sunNow RTBC for real.
1247 passes, 0 fails, 0 exceptions
Comment #11
dries commentedCommitted to CVS HEAD. Thanks!