Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Fix sorting bug in sorting of tagged services by priority #45399

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

Merged
merged 1 commit into from
Feb 11, 2022

Conversation

Ahummeling
Copy link
Contributor

Fixed incorrect assumption that the minimum priority is zero
leading to an unsorted list of negative priorities.

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #45396
License MIT
Doc PR

Fixed an incorrect assumption that the minimum priority is zero which was leading to an unsorted list of negative priorities.
(See #45396)

@dkarlovi
Copy link
Contributor

@Ahummeling if I understood correctly, it means the positive priorities are sorted correct, but negative are not?

Is sortTaggedServicesByPriority used to actually inject the services into the serializer? It seems unfortunate we'd have one method sorting them for display and another sorting them for injection, they'd always be in danger to go out of sync. 🤔

@Ahummeling
Copy link
Contributor Author

@Ahummeling if I understood correctly, it means the positive priorities are sorted correct, but negative are not?

Is sortTaggedServicesByPriority used to actually inject the services into the serializer? It seems unfortunate we'd have one method sorting them for display and another sorting them for injection, they'd always be in danger to go out of sync. thinking

Yes you are understanding this correctly.

The class responsible for sorting the output of the debug command is the Symfony\Bundle\FrameworkBundle\Console\Descriptor\Descriptor. I can't imagine this is used in the serializer, which would explain the differences.

@Ahummeling
Copy link
Contributor Author

The SerializerPass seems to call Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait::findAndSortTaggedServices
which has a completely different algorithm for sorting the services, but I believe it still initializes default priority to 0 in the case of the serializers. I am not quite sure how it works exactly, as it's quite a bit more complicated

@nicolas-grekas
Copy link
Member

Can you please add a test case?

@Ahummeling
Copy link
Contributor Author

Can you please add a test case?

Certainly, sorry should've done that before making the PR

Fixed incorrect assumption that the minimum priority is zero
leading to an unsorted list of negative priorities.
@Ahummeling
Copy link
Contributor Author

Added a test case to the relevant provider that would fail without the proposed change and updated the relevant fixtures to reflect this additional testcase.

@nicolas-grekas
Copy link
Member

Thank you @Ahummeling.

@nicolas-grekas nicolas-grekas merged commit a6aecb4 into symfony:4.4 Feb 11, 2022
This was referenced Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants