-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
NoSuchIndexException on DateType/TimeType fields when data class is null #47151
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
Comments
Can you create a small example application that allows to reproduce your issue? |
I attached the application files: controller, form type and twig template. I also attached the patched version. |
I cannot reproduce your issue. Using your code from the |
I found the problem on Symfony 5.4.10. I updated to 5.4.11 and the error is always there. I can attach the relevant config files, maybe there is some difference on form/validation settings. |
Can you push a complete application that I can check out and just execute? There may be other subtle differences. |
Ok, I attached a full application. Run composer to install Symfony 5.4 Anyway: if you disable in configuration the flag...
you will have no error, the datetime field is read without problems. No data lost. |
Status: Reviewed |
will be fixed by #47200 |
…o uninitialized arrays (xabbuh) This PR was merged into the 4.4 branch. Discussion ---------- [Form] ignore missing keys when mapping DateTime objects to uninitialized arrays | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #47151 | License | MIT | Doc PR | Commits ------- 6d79f68 ignore missing keys when mapping DateTime objects to uninitialized arrays
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
5.4
Description
I created a form without a Data Class, using fields with DateType or TimeType.
Submitting the form, this error is shown:
Cannot read index "xx" while trying to traverse path "[xx]". Available indices are "Array ...
The listed items of the array are only not DateType/ TimeType fields.
Note that in Symfony 4.4 I had no problems with it.
I think something is changed in form component, but I not found documentation about it.
How to reproduce
Simplified form example:
($option['dati'][1], $option['dati'][2], $option['dati'][3], $option['dati'][4] are all DateTime objects)
Possible Solution
The only way I found to avoid the error is to add a data transformer: DateTime to string. And then convert to DateTime in the controller.
This is the workaround:
Additional Context
Stack Trace
The text was updated successfully, but these errors were encountered: