-
-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Submit method in the FormController is executed twice. #11300
Comments
Are you able to replicate this on a fresh site? |
Not yet. Need to set up a new test site with the correct versions and such. Also have to copy all the helpers and customizations we did. Hopefully I get around to it this evening or tomorrow. But I just tested Statamic's mail job (instead of our custom one) and still got four e-mails (instead of the expected two), so it seems to me it's not the Job being a problem. |
So I can't get it reproduced on a fresh site, even though it is the same code. There are no duplicate requests happening there, also not on the same version as running on the live site. I did create a fresh site with a minimal install if you want to check it out, but I guess I will have to dig deeper. |
Small update, I have come up with the following logging, which whould indicate my AJAX is posting multiple times. [10:44:45] local.INFO: Posted to Statamic\FormController using AJAX. <-- Initial AJAX call, correct
[10:44:45] local.INFO: FormController calling SendEmails::dispatch due to Illuminate\Routing\Controller::callAction <-- SendMails dispatch byStatamic, correct but not queueing jobs?
[10:44:49] local.INFO: Posted to Statamic\FormController using AJAX. <-- A second unexplainable AJAX call, incorrect.
[10:44:49] local.INFO: SendEmails called by Statamic\Forms\SendEmails::dispatch <-- A second SendEmails dispatch by Statamic, incorrect (but kinda correct, because the first AJAX call did not queue jobs).
[10:44:49] local.INFO: MailJob added to queue by Statamic\Forms\SendEmails::Statamic\Forms\{closure} <-- MailJob for email config 1, correct.
[10:44:49] local.INFO: MailJob added to queue by Statamic\Forms\SendEmails::Statamic\Forms\{closure} <-- MailJob for email config 2, correct.
[10:44:49] local.INFO: FormController calling SendEmails::dispatch due to Illuminate\Routing\Controller::callAction <-- Huh?!
[10:44:49] local.INFO: SendEmails called by Statamic\Forms\SendEmails::dispatch <--A third SendEmails dispatch byStatamic, incorrect (but is adding jobs to the queue this time??)
[10:44:49] local.INFO: MailJob added to queue by Statamic\Forms\SendEmails::Statamic\Forms\{closure} <-- MailJob for email config 1, incorrect, is a duplicate.
[10:44:49] local.INFO: MailJob added to queue by Statamic\Forms\SendEmails::Statamic\Forms\{closure} <-- MailJob for email config 2, incorrect, is a duplicate. In the network tab, all is see is the following request. (To which I added a timestamp to make sure they are not grouped or anything by the DevTools). The Long story short, I am stumped. |
Do you have any event listeners?
How are you running your queue worker in production? With Redis as well? Are you using Laravel Horizon, or the default |
There is no event listeners regarding forms, so that'd be a no I guess. Queue redis is used on my local environment, prod is using sync (just found that out, nice). But I observe the same behaviour on both environments. |
Are you able to provide access to the site with the issue? You can either add me on GitHub ( |
No need Duncan! We've solved the issue. We had a middleware to set a default locale that was not ignoring Statamic's action routes. But it was not throwing errors or anything ofcourse so it proved to be a difficult little bugger to find. So, definitely user error on our part, thanks for the suggestions and excelent help, as always! |
Thanks for the update! |
Bug description
So I have set up forms using the Statamic routing, but with a custom MailJob. Now it seems that the FormController's submit method is executed twice even though there is only one request, causing me to have duplicate emails being sent out.
This did seem like a front-end issue, but with some pointers from Erin in the Discord, we've basically ruled that out.
So I'm turning to the help of the Github issues, since I've got no clue anymore. Now this might full-well be user error, but I don't see where that user error would be. So any pointers are appreciated.
After testing with Postman, like below, and adding logging directly in the Statamic FormController, I see these logs appearing. (Yes the log entries are older but I can still reproduce it.)
Since there is only one request, it seems to me there should only be one log entry, but that is not the case.
I'm submitting the form through AJAX, which looks as follows;
We do have a custom MailJob, which looks as follows, but it does not seem like this has anything to do with the root-cause of the issue since the jobs run AFTER the submit method in FormController was executed.
How to reproduce
Honestly, no clue.
I guess you can setup a form and try to post it using AJAX and see the same result.
Logs
No response
Environment
Installation
Fresh statamic/statamic site via CLI
Additional details
No response
The text was updated successfully, but these errors were encountered: