-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RC][Form] Let null values clear fields in PATCH requests #9146
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
Conversation
Can you please add a test case? |
I'm doing a rebase since there are some commits in between |
$form->setData($author); | ||
$form->submit(array('lastName' => null), false); | ||
|
||
$this->assertNull($author->getLastName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I seem to have given too little information here. The current test cases for this functionality are located in CompoundFormTest:85++, so we should also add this test case there. For example:
public function testSubmitForwardsNullIfNotClearMissingButValueIsExplicitlyNull()
{
$child = $this->getMockForm('firstName');
$this->form->add($child);
$child->expects($this->once())
->method('submit')
->with($this->equalTo(null));
$this->form->submit(array('firstName' => null), false);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry for that! Going to add this too.
Ok Added that test too and rebased |
Awesome, thanks. You can remove the other test. Could you also squash the commits into the first one please? |
Rebased and squashed ;) |
Are there any guidelines in where to write tests depending on what to test? So next time I write it correctly on first time :) |
This might be related to #8412 |
@alex88 Thanks! :) The best thing is to check where the modified functionality is currently tested and to add new tests there. If there are multiple tests for some functionality, you should go to the tests for the lowest layer in the architecture (for example, |
@bschussek thanks for the tip! I'll watch more carefully next time! |
…ra field. (jenkoian) This PR was squashed before being merged into the 2.3 branch (closes #10251). Discussion ---------- [Form][2.3] Fixes empty file-inputs getting treated as extra field. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8575 (#8575 (comment)) | License | MIT Re-applies 968fe23 (PR #8575). The test for this already exists, it was just this line that got overwritten by eb9f76d#diff-ca5e25b47f3ecc94cd557946aeb486c6L542 To clarify, this is a PR into 2.3 branch - this already exists in 2.4 (and later from this PR: #9146) Commits ------- 8d99d75 [Form][2.3] Fixes empty file-inputs getting treated as extra field.
…ra field. (jenkoian) This PR was squashed before being merged into the 2.3 branch (closes #10251). Discussion ---------- [Form][2.3] Fixes empty file-inputs getting treated as extra field. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8575 (symfony/symfony#8575 (comment)) | License | MIT Re-applies 968fe23 (PR #8575). The test for this already exists, it was just this line that got overwritten by symfony/symfony@eb9f76d#diff-ca5e25b47f3ecc94cd557946aeb486c6L542 To clarify, this is a PR into 2.3 branch - this already exists in 2.4 (and later from this PR: symfony/symfony#9146) Commits ------- 8d99d75 [Form][2.3] Fixes empty file-inputs getting treated as extra field.
…ra field. (jenkoian) This PR was squashed before being merged into the 2.3 branch (closes #10251). Discussion ---------- [Form][2.3] Fixes empty file-inputs getting treated as extra field. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8575 (symfony/symfony#8575 (comment)) | License | MIT Re-applies 968fe23 (PR #8575). The test for this already exists, it was just this line that got overwritten by symfony/symfony@eb9f76d#diff-ca5e25b47f3ecc94cd557946aeb486c6L542 To clarify, this is a PR into 2.3 branch - this already exists in 2.4 (and later from this PR: symfony/symfony#9146) Commits ------- 8d99d75 [Form][2.3] Fixes empty file-inputs getting treated as extra field.
…ra field. (jenkoian) This PR was squashed before being merged into the 2.3 branch (closes #10251). Discussion ---------- [Form][2.3] Fixes empty file-inputs getting treated as extra field. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8575 (symfony/symfony#8575 (comment)) | License | MIT Re-applies 968fe23 (PR #8575). The test for this already exists, it was just this line that got overwritten by symfony/symfony@eb9f76d#diff-ca5e25b47f3ecc94cd557946aeb486c6L542 To clarify, this is a PR into 2.3 branch - this already exists in 2.4 (and later from this PR: symfony/symfony#9146) Commits ------- 8d99d75 [Form][2.3] Fixes empty file-inputs getting treated as extra field.
I've changed the way form checks wherever or not to submit childs by checking submitted data with array_key_exists and not with just isset.
This way in PATCH requests values are not processed when they are not in array and not also when the value is null. Currently there is no way to null a value with a PATCH request, even passing it null.
This can lead to some BC breaks depending on how users used form in their code.