-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Description
Symfony version(s) affected: 4.4.7
Description
Error based on php.ini upload_max_filesize is thrown two time if the file entity form is nested in the form of another entity (e.g. a Company and a Logo entities) AND the file entity itself has a File or Image constraint.
Steps to reproduce
You can download the "bug reproducer" here: https://github.com/thibaut-decherit/nested-file-entity-bug
Make sure you have upload_max_filesize = 2M in your php.ini.
Go to localhost:8000/new and submit an image larger than 2Mo.
Two errors should appear instead of one.
Assumption
It's like the file size is validated prior to @Assert\Image() in src/Entity/Logo.php (maybe by the form itself or indirectly through a caught exception?) then a second time by @Assert\Image(), this time properly overwritten by maxSize="2M" (note the [...] size is 2 MB instead of [...] size is 2 MiB):

Note that if you remove @Assert\Valid() from src/Entity/Company.php only the first error is thrown:

(but @Assert\Image() is ignored so it is not a solution, you can confirm this by trying to submit a file other than jpeg, you will not get an error)