Problem/Motivation
When a priority is added to tags named 'http_client_middleware', the priority is ignored. HTTP client middlewares should use standard service_id_collector
so priorities work out of the box.
Steps to reproduce
Create two HTTP middlewares, define them like so:
test.http_middleware1:
class: Drupal\test\HttpMiddleware1
tags:
- { name: http_client_middleware, priority: -100 }
test.http_middleware2:
class: Drupal\test\HttpMiddleware2
tags:
- { name: http_client_middleware, priority: 100 }
You'll see the first middleware is executed first, since it's defined first. Instead the second middleware should be executed first since priorities work in highest->lowest order.
Proposed resolution
Deprecate \Drupal\Core\DependencyInjection\Compiler\GuzzleMiddlewarePass
and replace with service_id_collector
.
Release notes snippet
GuzzleMiddlewarePass has been removed in favor of the generic TaggedHandlersPass, code interacting with GuzzleMiddlewarePass should use TaggedHandlersPass instead.
Comment | File | Size | Author |
---|---|---|---|
#6 | 3215397-6.patch | 2.5 KB | dhirendra.mishra |
#2 | 3215397-http-service-tag.patch | 1.81 KB | dpi |
Comments
Comment #2
dpiI'm at a loss for how to test this in a Kernel test, so posting the fix as I have it.
Comment #3
dpiComment #4
longwaveNice find!
Pretty sure compiler passes are considered internal anyway, we can hopefully just remove the class and the reference to it in CoreServiceProvider.
Not sure we need a test either, as TaggedHandlersPassTest covers this case and we're just using it as intended here rather than a custom pass that does something similar but not as well.
As a followup it looks like ContextProvidersPass could have the same treatment, it is very similar.
Comment #5
longwaveRemembered this following discussion of Guzzle middleware in another issue.
I think we can remove the GuzzleMiddlewarePass entirely, there is no need to keep it around.
Comment #6
dhirendra.mishra CreditAttribution: dhirendra.mishra at Valuebound for Valuebound commentedI have remove GuzzleMiddlewarePass occurance..Please review it if it hepls.
Comment #7
longwaveThanks, this looks correct to me, and I don't see the value in adding an explicit test although core committers might decide otherwise.
Comment #8
larowlanI've pinged other committers about the BC implications (if any) here
Comment #9
larowlanDiscussed the BC implications with catch who felt that these would be similar to Param converters
Can we get a change notice for the removal of the class?
Thanks
We'll update the BC policy to explicitly list compiler passes when this goes in
Comment #10
longwaveAdded https://www.drupal.org/node/3223749
Comment #11
larowlanSaving issue credits for longwave for writing the change record 💾
Updated the BC policy
Added a release notes snippet.
Verified there's no contrib usage of this
Comment #13
larowlanCommitted 02e787a and pushed to 9.3.x. Thanks!
Published the change record
Comment #14
larowlanI feel this is a bug, if priorities are ignored.
We could do this, however its less important there because by nature of how they work, contexts don't typical interact with each other and hence priority isn't important.
By their very nature, middlewares are expected to be reliably ordered, so that's why I've reclassified it as a bug.
Comment #15
dpiThanks @larowlan, thanks @longwave for the CR
Comment #16
alexpott