Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Form] Fixed edge case where empty data may not be a string and throws TransformationFailedException#13598
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
… it throws a TransformationFailedException with message: 'Expected a string.'.
guilhermeblanco commentedFeb 4, 2015
After investigating more on how I hit this corner case, I have more information. |
Tobion commentedFeb 4, 2015
Definitely needs tests |
Tobion commentedFeb 4, 2015
Also see#5939 |
guilhermeblanco commentedFeb 5, 2015
@Tobion I completely understand that quoted value leads to proper response. That's what I'm using internally in address this issue. |
stof commentedMar 19, 2015
In any case, this cannot be accepted without tests |
fabpot commentedMay 16, 2015
@guilhermeblanco Any chance you can add some tests? |
guilhermeblanco commentedMay 17, 2015
@fabpot I need to remember the situation that I hit it, but yes, I can add tests for this. =) |
webmozart commentedJun 18, 2015
Thank you for submitting this PR@guilhermeblanco! This is a duplicate of#12470. The underlying problem here is#4715, which can't be fixed without breaking BC. Every other solution is unfortunately a hack. I recommend that you use a custom model transformer that sets your default value instead until#4715 is fixed. |
guilhermeblanco commentedJun 18, 2015
@webmozart Yes, it is a duplicate. However, can you explain me how does this solution qualify as a BC break? |
webmozart commentedNov 6, 2015
Reopened after talking to@guilhermeblanco in person. This solution makes sense. Could you please rebase this on 2.3 and add tests? |
fabpot commentedJan 25, 2016
@guilhermeblanco Any news on this one? |
guilhermeblanco commentedJan 25, 2016
@fabpot should be able to do it in the next few days. =) |
fabpot commentedFeb 18, 2016
@guilhermeblanco Sorry for being pushy, but we try hard to merge/close old PRs. Any chance you can have a look at this one? |
guilhermeblanco commentedFeb 29, 2016
@fabpot I've spent a substantial amount of hours trying to recreate this scenario on both SimpleFormTest and CompoundFormTest without success. |
HeahDude commentedFeb 29, 2016
I've tried to add tests in Here's what I've tried : publicfunctiontestSubmitNull(){$form =$this->factory->create('integer');$form->submit(null);$this->assertNull($form->getData());$this->assertNull($form->getViewData());}publicfunctiontestSubmitNullWithEmptyData(){$form =$this->factory->create('integer',null,array('empty_data' =>1, ));$form->submit(null);$this->assertSame(1,$form->getData());$this->assertSame('1',$form->getViewData());}publicfunctiontestSubmitNullWithEmptyDataWhenNested(){$form =$this->factory->create('form') ->add('age','integer',array('empty_data' =>1, ));$form->submit(null);$this->assertSame(1,$form->get('age')->getData());$this->assertSame('1',$form->get('age')->getViewData());} |
jakzal commentedMar 1, 2016
@HeahDude IntegerTypeTest requires the intl extension (have a look at the setUp() method). |
HeahDude commentedMar 1, 2016
@jakzal thanks, will take another look though. |
HeahDude commentedMar 1, 2016
@jakzal, I've checked and I have intl installed, but tests are skipped even with my global phpunit. Any lead ? |
jakzal commentedMar 1, 2016
@HeahDude if I remember correctly it needs to be installed in a specific version. You'll need to look into the code that makes the check. |
webmozart commentedMar 2, 2016
@HeahDude PHPUnit tells you why a test was skipped if you pass the #14260 proposes to upgrade to ICU 55.1, which would solve your problem. Would you like to work on that ticket? |
fabpot commentedMar 3, 2016
IIUC, the change is good but we don't know (yet) how to write good unit tests to avoid regressions, is that correct? |
guilhermeblanco commentedMar 3, 2016
@fabpot correct. Patch addresses nicely the problem in the known scenario: 2 integer fields with empty_data as integer values and submitting only one of the values (thus requiring the second to use the empty_data). |
fabpot commentedMar 4, 2016
Understood. So, instead of waiting for tests, and because this is a bug fix that is waiting here for so long, I propose to merge this as is for now. ping @symfony/deciders |
webmozart commentedMar 4, 2016
@fabpot I'll talk to@guilhermeblanco and try to create some tests. If we don't, chances are that this gets refactored away again when optimizing the |
HeahDude commentedMar 4, 2016
@guilhermeblanco, is the form compound in your scenario ? I think it may be either not relevant or some cause of this problem. |
weaverryan commentedMar 6, 2016
I'm fine to have this merged - as long as we don't have any BC concerns. If this introduces an edge-case behavior change, I'm not clearwhat that change is - I'd like to see the before/after code in an UPGRADE file. I want to avoid this causing upgrade issues - it sounds like something that would be quite hard to track down. |
xabbuh commentedMar 7, 2016
I took@guilhermeblanco's commit and the tests suggested by@HeahDude (with a minor change where the view data are not expected to be |
HeahDude commentedMar 7, 2016
Nice job! I would suggest: // CheckBoxTypeTest.phppublicfunctiontestSubmitNullWithEmptyDataTrueWhenNested(){$form =$this->factory->create('form') ->add('agree','checkbox',array('empty_data' =>true, ));$form->submit(null);$this->assertTrue($form->get('agree')->getData());$this->assertSame('1',$form->get('agree')->getViewData());$view =$form->get('agree')->createView();$this->assertTrue($view->vars['checked']);}publicfunctiontestSubmitNullWithEmptyDataFalseWhenNested(){$form =$this->factory->create('form') ->add('agree','checkbox',array('empty_data' =>false, ));$form->submit(null);$this->assertFalse($form->get('agree')->getData());$this->assertEmpty($form->get('agree')->getViewData());$view =$form->get('agree')->createView();$this->assertFalse($view->vars['checked']);} And I confirm those tests fail without the fix. |
xabbuh commentedMar 7, 2016
@HeahDude Thanks, test added. |
webmozart commentedMar 14, 2016
Closed for the reasons discussed in#18047. |
I just can't recreate this error, by any means.
I somehow have a form with an integer type which happens to submit "null" as
viewData(somehow) and it reusesempty_dataoption. Now my field was configured like:And since the assignment of
viewDatais theempty_data, one of the normalizers (while callingviewToNorm()) throws aTransformationFailedExceptionwith the following message:Expected a string.