Problem/Motivation
Since #3423454: Form Builder does not fully allow Ajax GET requests, FormBuilder::buildForm() throws BrokenPostRequestException when a request has the ajax_form query parameter but no form_id. The check is meant for POST requests truncated by post_max_size, but it also runs for GET requests. This happens when a form submitted with Ajax redirects to itself: the URL becomes /foo?ajax_form=1&_wrapper_format=drupal_ajax, and the browser follows it with GET.
Steps to reproduce
- Use a form that is submitted with Ajax and redirects to the same page after submission.
- Submit the form. The redirect is a GET request with
ajax_form=1&_wrapper_format=drupal_ajax. - The form is not shown. The response contains the error "An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (2 MB) that this server supports."
Shorter way: as an anonymous user, open /user/login?ajax_form=1. The same error is shown instead of the login form.
Proposed resolution
Only throw the exception for POST requests. GET requests with ajax_form are built normally.
Remaining tasks
Review.
User interface changes
None.
API changes
None.
Data model changes
None.
AI usage
An LLM helped with the test fix in MR !17294 and with this summary. The steps to reproduce were checked on main.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | before.png | 91.23 KB | anchal_gupta |
| #9 | after.png | 223.89 KB | anchal_gupta |
| #3 | 3443176.patch | 760 bytes | mkalkbrenner |
Issue fork drupal-3443176
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mkalkbrennerComment #3
mkalkbrennerComment #4
smustgrave commentedThanks for reporting. Sounds like something that may need test coverage, 60/40 on that. Since it's a small change but is marked major.
Comment #7
sahana _n commentedHi,
I tried to reproduce the issue in Drupal 11. x and successfully the issue is reproduced.
Reproducing steps
1. Install Drupal Core 11.x
2. Created the custom form with the file element.
3. On submission called Ajax callback.
I created an MR please review it.
If there are any inaccuracies, I would greatly appreciate your suggestions for improvement.
Thanks!!
Comment #8
smustgrave commentedPreviously tagged for tests which still appear to be needed
Also MR appears to be the same as the patch, was there any change?
Comment #9
anchal_gupta commentedI have test this issue with the latest merge request. Its working fine as per expectation.
Also attach screenshot.
Comment #13
brandonlira commentedOpened a new MR against current main: MR!17294.
The previous MR was significantly behind main and had conflicts, so I recreated the change on a fresh branch.
This keeps BrokenPostRequestException limited to broken AJAX POST submissions and adds direct test coverage for AJAX GET form requests with ajax_form=1 but no form_id.
Comment #14
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #16
mehdi.najeddine commentedPushed a commit to MR !17294. It replaces the @legacy-covers annotation on testGetAjaxRequestWithoutFormId with @see ::buildForm. Core PHPStan no longer allows @legacy-covers on test methods, which caused the failure reported by the bot. With the FormBuilder.php change reverted, testGetAjaxRequestWithoutFormId fails with BrokenPostRequestException. With the change, all 51 tests in FormBuilderTest pass, and the form unit and kernel tests pass too.
Generated with the help of an LLM.
Comment #17
smustgrave commentedCan the summary template be updated, can mention use of AI there too.
But as a bug should have the steps to reproduce section
Comment #18
mehdi.najeddine commentedUpdated the issue summary with the bug template and steps to reproduce. The AI use is noted there.
Generated with the help of an LLM.
Comment #19
mehdi.najeddine commented