-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Regression in Form extension since 3.2 #20332
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
Fixed using priority on the service definition: <service id="yolo_csrf" class="YoloCsrfDisablerExtension">
<argument type="service" id="request_stack"/>
<tag name="form.type_extension" priority="-5" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
</service> |
The regression seems to indicate that the sorting does not preserve the order of extensions having the same priority. We should fix that to avoid BC breaks |
I do not agree on this, if it worked before it was a kind of "luck" that we should avoid. That's why having priorities is good because if extensions depend on each other, then it should be done carefully. Either by registering a form extension to add them in the order one needs, or thanks to the new feature of the full stack. |
@HeahDude I don't agree with you on:
Before adding the priority option, the form-extensions were loaded in the order defined by::
Adding the |
@francoispluchino Hi, I understand your points.
Yes, an order very fragile, easy to break without noticing, and really hard to maintain IMHO. Now again I really think they should be 2 ways of being explicit about extensions "order" for sure:
This is the best to be in full control here, but ok, this is just my opinion. What I think is that breaking it now like this, just reveals some inconsistencies in the code, and once fixed with one of the ways I've proposed, it is a safer thing for the future. Extensions were not meant to "extend" each other in the first place, so we have to make some compromise. |
Make this change for a new major release (ex. Even though the extensions were not intended to extend each other, this scenario often occurs with libraries, and the order of adding Bundles was not hazardous. The problem is that changing this behavior was introduced in a new minor version ( This change should have been done for the version |
The problem is that we cannot deprecate this kind of behavior and we also maintain upgrade files for minor releases. So it would have broken the same in 4.0, without being able to get some notice before, just by reading the upgrade file :/
This is exactly what I'm talking about, it's just about being more explicit, easy to understand and to solve, because then how do you handle two bundles when one needs some service to be registered first and the other needs this one, this is not manageable by bundle ordering. Such use cases for services in different bundles that need priorities because they share some tag should be able to define a priority. Maybe we (mostly I in this case, so sorry about that) need to be more careful in the future to prevent such BC break, but reverting it now might break applications now using priorities :( So I don't kn 8000 ow what to say now. |
Is this php7 only? Php7 uses non stable sorting algos, on the contrary to php5. |
@nicolas-grekas No, at least since php5.3, see: SplPriorityQueue is not a FIFO implementation. With the php7, the performance has improved, but php7 still did not fix the problem. There are several solutions to maintain performance and achieve the expected behavior:
Alternatively, we can use the old method: // Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait
private function findAndSortTaggedServices($tagName, ContainerBuilder $container)
{
$services = array();
foreach ($container->findTaggedServiceIds($tagName) as $serviceId => $tags) {
foreach ($tags as $attributes) {
$priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
$services[$priority][] = new Reference($serviceId);
}
}
// sort by priority and flatten
if (count($services) > 0) {
krsort($services);
$services = call_user_func_array('array_merge', $services);
}
return $services;
} |
@francoispluchino see #20993 :) |
I just saw your PR. My previous example is not more simple? |
I'm not sure about that, we have to do a first triage by extended type https://github.com/symfony/symfony/pull/20993/files#diff-a5475cdc6eb4006880d92f461fba8034R63. |
I don't think it's necessary, because the order is preserved. So each extended-type will have a correct priority order. After, regarding the performance, I did not check, but I guess that 1 |
Yeah what about fixing your issue? :) |
@nicolas-grekas @HeahDude See the PR #20995. |
…ass trait (francoispluchino) This PR was merged into the 3.2 branch. Discussion ---------- [DependencyInjection] Fix the priority order of compiler pass trait | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20332, #20993 | License | MIT | Doc PR | ~ A regression has appeared between the version `3.1` and `3.2` on the compilation passes using a priority option (see #20332). Indeed, the order is no longer preserved for service definitions with the same priority. This is caused by the `SplPriorityQueue` class that does not have a FIFO implementation (see this [comment](#20332 (comment))). The PR #20993 fixes the problem but only for Forms, not for all compiler passes using the `PriorityTaggedServiceTrait` trait since `3.2`. Commits ------- aac9a7e Fix the priority order of compiler pass trait
…ass trait (francoispluchino) This PR was merged into the 3.2 branch. Discussion ---------- [DependencyInjection] Fix the priority order of compiler pass trait | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20332, #20993 | License | MIT | Doc PR | ~ A regression has appeared between the version `3.1` and `3.2` on the compilation passes using a priority option (see #20332). Indeed, the order is no longer preserved for service definitions with the same priority. This is caused by the `SplPriorityQueue` class that does not have a FIFO implementation (see this [comment](symfony/symfony#20332 (comment))). The PR #20993 fixes the problem but only for Forms, not for all compiler passes using the `PriorityTaggedServiceTrait` trait since `3.2`. Commits ------- aac9a7e Fix the priority order of compiler pass trait
Since Symfony 3.2 RC 1, I see a regression in my web app: I have a form extension that disable csrf-protection on the
/yolo/*
routes:Prior to Symfony 3.2, when I submitted a form that failed on validation, errors returned by the form submission returned something like:
The value should not be blank
.Since Symfony 3.2, even if the form extension is enabled, I now got two errors:
The value should not be blank
andThe CSRF token is invalid. Please try to resubmit the form.
that should not appear since the option is disabled with my extensionThe text was updated successfully, but these errors were encountered: