Skip to content
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

Overlapping routes with captures having different names panics #2218

Closed
1 task done
DMaxter opened this issue Sep 9, 2023 · 4 comments
Closed
1 task done

Overlapping routes with captures having different names panics #2218

DMaxter opened this issue Sep 9, 2023 · 4 comments

Comments

@DMaxter
Copy link

DMaxter commented Sep 9, 2023

  • I have looked for existing issues (including closed) about this

Bug Report

Version

axum v0.6.20
├── axum-core v0.3.4

Platform

Linux zirconium 6.4.12-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Thu, 24 Aug 2023 00:37:46 +0000 x86_64 GNU/Linux

Description

Cannot have 2 routes with different parameters and different methods, as I receive an error stating there is a conflict

I tried this code:

use axum::{
    routing::{post, put},
    Router, Server,
};

#[tokio::main]
async fn main() {
    Server::bind(&"0.0.0.0:8000".parse().unwrap())
        .serve(
            Router::new()
                .route("/:name", post(|| async {}))
                .route("/:id/:name", put(|| async {}))
                .into_make_service(),
        )
        .await
        .unwrap();
}

I expected to see no error, however, I got this: Invalid route "/:id/:name": insertion failed due to conflict with previously registered route: /:name

This is just a reproducer as in a real service, I use Path(id): Path<i64> and Path(name): Path<String>, however, it still gives me the same error. Is this some kind of bug?

I looked at the MethodRouter and the issue that motivated its implementation, however MethodRouter doesn't seem to be the correct approach here, but correct me if I am misunderstood

@davidpdrsn
Copy link
Member

This is because of ibraheemdev/matchit#13. See that issue for a workaround.

Since it's a bug in one of axum's dependencies there isn't anything we can do about it. Though its hopefully going to be fixed in the next major version of axum (which will include the next major of matchit)

@davidpdrsn davidpdrsn closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2023
@DMaxter
Copy link
Author

DMaxter commented Sep 10, 2023

There is no workaround mentioned in that issue

@davidpdrsn
Copy link
Member

davidpdrsn commented Sep 10, 2023

Yes there is:

but only if they have a common prefix

@DMaxter
Copy link
Author

DMaxter commented Sep 10, 2023

Oh, missed that part, thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants