-
Notifications
You must be signed in to change notification settings - Fork 411
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
Fix Route merge order to fix Issue #3066 #3160
base: main
Are you sure you want to change the base?
Conversation
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.
I'm a little bit confused. ++
should be left-associative, so why / how does this work exactly? AFAICT this should be breaking things 😕
Also, can you please add the reproducer as a test that was added in the original issue?
EDIT / PS: If this is indeed the solution to the issue, I think we should be fixing ++
instead and adding tests to ensure that it's left-associative
As far as understand, doing I agree that I would have expected routes to be merged route-by-route, but figured that there probably was a good reason to just put then in a list. |
Adding the test case is complicated because it depends on TestServer, which is afaik not usable in zio-http because it would lead to circular dependencies. |
Even if this works, this is not how |
@987Nabil Do you mean that the request handlers should be constructed from the routes iterating back to front over them or do you mean that the request handler tree building code should read front to back but override older values or at least prefer newer ones? |
I updated the PR to change the handler merging logic in cases of multiple handlers for the same path. |
Since the new code is more general, i also got rid of the special casing between one handler and more than one handler. |
In case of duplicate routes, the old logic gives precedence to older routes, which breaks cases where the routes are updated with new environments and re-added. This gives precedence to the newer ones. /claim zio#3066
Lot's of tests failing, I'll check what's up with that. |
This change does not look right either. Neither the place nor the fact that we replace a while loop with allocation of an interator |
@987Nabil Then i'm not sure what the intended behaviour is. Routes uses the normal And since the chunks and therefore the handlers are put into "oldest left" order and the handler building iterates left-to-right, the oldest one gets preference every time. AlternativeI could change the |
@guizmaii @jdegoes I went through a couple of iterations in this PR already but I'm now a bit lost on what the desired solution is. |
@kyri-petrou @987Nabil Turns out, our notion of how zio-http/zio-http/shared/src/main/scala/zio/http/Routes.scala Lines 51 to 57 in 502331c
It seems like "old (left) has precedence over new (right)" is the intended behaviour. |
@jdegoes I find this behaviour confusing. Everywhere else we give "the new thing" precedence. Should we change it? |
In case of duplicate routes, the old logic gives precedence to older routes, which breaks cases where the routes are updated with new environments and re-added.
This gives precedence to the newer ones.
/claim #3066