Simultaneous AJAX submissions result in form cache not getting updated for the second submission.
First AJAX request enters with form_id: form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw
New form is built with new form_id: form-JR1EXYiJjXD6F4YgT2Dkq_sd2oJcSQfr1g-9Ai8MDK4
Response contains
{
"command": "update_build_id",
"old": "form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw",
"new": "form-JR1EXYiJjXD6F4YgT2Dkq_sd2oJcSQfr1g-9Ai8MDK4"
}
which updates form_build_id using update_build_id in ajax.js
update_build_id: function (ajax, response, status) {
$('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
}
Second AJAX request enters with same original form_build_id as first form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw
New form is built with form_id: form-CyMki8IJH0TDuqWVj3Hn0DMqrYvIoNyviLbKcJfosoc
Response contains
{
"command": "update_build_id",
"old": "form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw",
"new": "form-CyMki8IJH0TDuqWVj3Hn0DMqrYvIoNyviLbKcJfosoc"
}
however as form_build_id was updated by first request, the input field is not found in update_build_id.
Proposed change is to update form_build_id without using value if only one form exists on the page.
update_build_id: function (ajax, response, status) {
var build_ids = $('input[name="form_build_id"]');
if (build_ids.length == 1) {
$('input[name="form_build_id"]').val(response.new);
} else {
$('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
}
},
or update the form_build_id without using value if one cannot be found with the value of response.old
update_build_id: function (ajax, response, status) {
var old_build_id = $('input[name="form_build_id"][value="' + response.old + '"]');
if (old_build_id.length == 0) {
$('input[name="form_build_id"]').val(response.new);
} else {
$('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
}
}
Repro steps:
- click two ajax buttons at the same time (the second button must be clicked before the first one finishes processing). refer to image 1
- search through the response of each ajax submission for "update_build_id" and copy that whole command somewhere for reference. refer to image 2
- compare two responses. they will have the same "old" build id. refer to image 3
alternatively, you can put a breakpoint at the update_build_id function in core/misc/ajax.js and inspect the response data.
Comment | File | Size | Author |
---|---|---|---|
#24 | 2871829-nr-bot.txt | 129 bytes | needs-review-queue-bot |
#13 | patch2c.patch | 1.07 KB | RaisinBranCrunch |
#13 | patch1c.patch | 1.04 KB | RaisinBranCrunch |
#10 | patch2a.patch | 670 bytes | RaisinBranCrunch |
#10 | patch1a.patch | 634 bytes | RaisinBranCrunch |
Comments
Comment #2
Tyler_Rivard CreditAttribution: Tyler_Rivard commentedThis issue severely effects modules that modify the form like inline_entity_form.
Comment #3
Tyler_Rivard CreditAttribution: Tyler_Rivard commentedComment #4
cilefen CreditAttribution: cilefen commentedPlease put code tags around the code samples in the issue summary.
Comment #7
sudhanshug CreditAttribution: sudhanshug as a volunteer and at Google Summer of Code commentedComment #9
RaisinBranCrunch CreditAttribution: RaisinBranCrunch commentedI don't understand why the patches failed.
fatal: corrupt patch at line 21
What does that mean? The patches end with newline... they applied fine on my system...
I remade them, and I'm attaching them again.
Comment #10
RaisinBranCrunch CreditAttribution: RaisinBranCrunch commentedTrying something else after Googling some things...
Patch files are different sizes, is that a good sign? ...
Comment #13
RaisinBranCrunch CreditAttribution: RaisinBranCrunch commentedOkay, patch1 and patch2 failed because they were edited with nano, which messes them up apparently. Patch1a and patch2a failed because I used 8.3.7 and not 8.4.x-dev... let's hope these ones work... they successfully apply to my 8.4.x-dev site.
Comment #14
joelpittetThis may be tricky but could follow the reproduce steps and the code is easy to review.
Nice cleanup of the previously identified named function being removed, BTW;)
Comment #16
joshmillerComment #24
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.