Selecting a file results in 400 Bad Request Ajax Response if selection happens immediately after creating the record
Affected version(s)
5.4.3
Description
Steps to reproduce in demo.contao.org:
- login as k.jones (admin)
- click on "themes"
- click on "new"
- Without doing anything else first, click on "Change selection" of the "Screenshot" field to open the filepicker.
- Select any file
- Click "Apply" to select the file
The file will not be selected. Network Tools show a 400 Bad Request Error from the Ajax Request:
This is not a problem specific to the Theme module. The Theme module is just the easiest place to reproduce the issue in the demo installation as it is one of the few places one can open the filepicker immediately after creating a new record, without loading a different (sub)palette first by checking a checkbox or selecting a type. Even just clicking on "new theme" and refreshing the empty form before opening the filepicker will prevent the error from happening. This problem occurs anywhere if the initial palette (not necessarily "default" palette) allows to select a file. In my installation this happens in custom modules and also for the content element "Image" if permissions for a user are set in a way that "Image" is the default type being loaded, so that the content element "type" does not need to be changed to "Image" before opening the picker.
In my logs i can see the 400 error is raised by Ajax.php:231 by a missing parameter "id"
[2024-10-17T16:43:51.460490+02:00] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\BadRequestHttpException: "Bad request" at Ajax.php line 231 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\BadRequestHttpException(code: 0): Bad request at /usr/www/users/maschu/2024/dev/vendor/contao/core-bundle/contao/classes/Ajax.php:231)"} {"request_uri":"https://XXXXXXXXXXXXX/contao?do=mariContentPublication&id=2&ref=1DSQfILQ&rt=2e2414a29f5b3b0166af50dd75aafda5.f5N3N2UtD0E09woeFTjssQnQ69ytnxWZpkHUoKq_5z0.KNQ1ZABEOhZEwUx7W3aPyDyzqrHr133t6nCVjf_HilAW9CEFNBhMbGLFeQ&table=tl_mari_publicationissue","request_method":"POST"}
I can not reproduce it in a normal installed demo (5.4, 5.x). This seems to be just related to demo.contao.org, most likely because there is modifications so you can not modify files in the online demo
I looked into reproducing it in a freshly installed 5.4.3 and at first it seemed to work but i found it requires an additional navigation step inbetween to trigger the error. Maybe i did that at some point in my initial tests without realizing it was necessary to trigger the behavior, sorry. I'll use the theme module again:
- login as admin (non-admin has the same issue but this is a fresh install, so all i have is the admin)
- go to themes
- click on new
- set title to "test" and autor to "test"
- save and close
- click on the modules icon of the new theme (works with layouts and image sizes as well. really just any submodule)
- go back to themes by clicking "themes" in the main navigation ("go back" button also works)
- click on new to create a second theme
- click on change selection for the screenshot input
- select any image and click apply
I can provide access to this installation if it is of any help.
This way i can replicate the error reliably in this fresh 5.4.3, in demo.contao.org, as well as 2 other websites running 5.4.3. The error does not happen in 5.3.x
Using these reproduction steps I was unable to reproduce the issue in Contao 5.4.x unfortunately.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
While I still wasn't able to reproduce this exactly, I did notice that if you click on Save directly after selecting a file (or changing it) the new file won't be saved. You don't even have to be that quick.
I cannot reproduce this in Contao 5.6. Pretty sure it has been fixed by https://github.com/contao/contao/pull/8036
I can still reproduce this in 5.6.x-dev.
That is a different issue though, and one that exists since forever. You should create a separate issue for it.
True 👍