Skip to content
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

Duplicate uploadIniSizeError if entity form is nested in the form of another entity #36503

Closed
thibaut-decherit opened this issue Apr 20, 2020 · 5 comments

Comments

@thibaut-decherit
Copy link

thibaut-decherit commented Apr 20, 2020

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)

@xabbuh
Copy link
Member

xabbuh commented Apr 20, 2020

Could it be the same issue as #32045?

@thibaut-decherit
Copy link
Author

Thank you for your feedback!

Yes and no.
#32045 seems to occur on any form with a file upload exceeding upload_max_filesize from php.ini, "my" bug only occurs if the FormType owning the file input is nested in another form.

I have not encountered this issue with nonnested forms. Furthermore, in my case all errors are properly translated.

@lmasforne
Copy link
Contributor

lmasforne commented Apr 27, 2020

As i see there two messages because you got one message with the FileType constraint of the Form component and one with the File constraint of the Validator component. I supposed when the same constraint is lauched, it could be merged in one same constraint ? I try to use xdebug your code when i post the file but it's extremly slow, what class is supposed to merge two constraint of different components ?

@thibaut-decherit
Copy link
Author

thibaut-decherit commented Apr 27, 2020

I supposed when the same constraint is lauched, it could be merged in one same constraint ?

I believe it is the expected behaviour, it does seem to work like that if the FormType with a file input is not nested in another FormType.

@xabbuh
Copy link
Member

xabbuh commented Nov 19, 2020

Can you please check if #39119 fixes this?

@fabpot fabpot closed this as completed Nov 27, 2020
fabpot added a commit that referenced this issue Nov 27, 2020
…mits (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Form] prevent duplicated error message for file upload limits

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #32045, #36503, #39107
| License       | MIT
| Doc PR        |

Commits
-------

fe6a2dd prevent duplicated error message for file upload limits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants