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 invalid state of non synchronized forms#20966
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
| publicfunctionisValid() | ||
| { | ||
| if (!$this->submitted) { | ||
| if (!$this->submitted ||$this->transformationFailure) { |
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.
- if (!$this->submitted || $this->transformationFailure) {+ if (!$this->submitted || !$this->isSynchronized()) {
?
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.
Performance wise, this function call is useless IMO.
ogizanagi commentedDec 16, 2016
Status: Reviewed then 👍 :) |
HeahDude commentedDec 16, 2016
@ogizanagi There is still a problem I think, we have now a potential invalid form without any error because the mapping is delegated to the validation extension of the form component... If other symfony deciders agree with this one we should find a way to attach the error closer in the core, but this would be a bigger BC break, and I need to think more about how to work around that. Suggestions are welcome though :) |
ogizanagi commentedDec 16, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Maybe I miss the point, but your changes won't change anything to the previous behavior, right? As soon as the validation extension is triggered on
Maybe we should, in order to make the form component working better without the validator component at least for transformation failures, but it's not the PR subject (and could be seen as an enhancement/feature). Or am I missing something? |
HeahDude commentedDec 16, 2016
This is true in the full stack as you said:
But this is more about the internal validation form extension, we're not even talking of the Validation component here. I agree it should be very rare to use the Form component without all its core extensions, but we still need to support such use cases. |
ogizanagi commentedDec 16, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Sure. The But, would indeed extracting the transformation failure mapping part to the |
HeahDude commentedDec 16, 2016
I've thought about that indeed but
is a BC break :) |
ogizanagi commentedDec 16, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
No, I meant skipping validation (transformation failures or validator related one) would still work as before. I actually miss the situation where extracting this logic from the validation extension to be enabled by default in the Form would be a(nother) BC break. ? In the worst case, it'll only add |
HeahDude commentedDec 16, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Ok, two cases:
So case 2 is dead, I'll try to explore the "first choice" and problem 1 later, or any other good suggestion that comes. |
ogizanagi commentedDec 16, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Why? If the logic is moved (not duplicated, moved from the validator extension to the Form), the error will not be mapped twice? It'll not be a BC break neither to me. The listener and validator are meant to be used with a form, so there is no other case where the logic about transformation failures will be missed.
Maybe. I can't argue against that ¯\(ツ)/¯, but right now I fail to see such cases. |
HeahDude commentedDec 16, 2016
If it's just moved, someone expecting this error mapping won't have it anymore. |
ogizanagi commentedDec 16, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Sorry, I've edited my comment after and, I think, answered that: It'll not be a BC break neither to me. The listener and validator are meant to be used with a |
HeahDude commentedDec 16, 2016
This can happen when extending the |
ogizanagi commentedDec 16, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Just asking: Is not calling the parent constructor something fully covered by the BC promise? A |
HeahDude commentedDec 16, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
If I were about to move the code from the validation listener I would probably move it to This is very unlikely, but this is possible. It would be better and not easier IMO, to try to avoid the duplication in the validation listener, and try to deprecate it in master to keep a migration path. I'll give a try to the solution 1, opened to other solutions :) |
ogizanagi commentedDec 16, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hence the solution I suggested about registering a diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.phpindex c8acaf8..78d5bde 100644--- a/src/Symfony/Component/Form/Form.php+++ b/src/Symfony/Component/Form/Form.php@@ -182,6 +182,8 @@ class Form implements \IteratorAggregate, FormInterface $this->config = $config; $this->children = new OrderedHashMap();++ $this->config->getEventDispatcher()->addListener(FormEvents::POST_SUBMIT, new TransformationFailedListener()); } public function __clone() If someone overrides |
HeahDude commentedDec 16, 2016
Yeah this is the case 2. |
xabbuh commentedJan 11, 2017
@HeahDude What is the state here? |
HeahDude commentedJan 11, 2017
Will be rebased on master since the is a major behaviorial change IMO which will come with a deprecation, but I'm working on fixing#20935 first. |
HeahDude commentedJul 6, 2017
Will target 3.4 with bigger changes. 2.7 is not targetable globally, we need to try to fix the ChoiceType only. Closing here for now. |
The approach of this patch fixes the valid state of any form (including
ChoiceType, see the related issue) for a minimal performance impact, but also introduces a minor BC break that we should allow in this case IMHO, because some data could be persisted with the pre set data ignoring an error occurring with a transformation failure and causing the field to not be synchronized, which looks really wrong to me.