sparckles / Robyn

Robyn is a Super Fast Async Python Web Framework with a Rust runtime.
https://robyn.tech/
BSD 2-Clause "Simplified" License
4.35k stars 227 forks source link

Authenticated routes with different method but same path causes conflict. #982

Open Rohithzr opened 1 week ago

Rohithzr commented 1 week ago

Bug Description

Authenticated Routes with different methods but same path throw the following error.

thread '<unnamed>' panicked at src/server.rs:347:14:
called `Result::unwrap()` on an `Err` value: insertion failed due to conflict with previously registered route: /auth/v1/profile

Expectation: The routes with same path but different methods should work without error.

Complete file: https://github.com/Rohithzr/robyn-template/blob/main/standalone.py Sample code:

@app.get("/health")
async def health():
    return {"status": "ok"}

@app.post("/health")
async def health_alt():
    return {"status": "ok"}

@app.get("/auth/v1/login")
async def login(request):
    return {"status": "ok"}

@app.get("/auth/v1/logout")
async def logout(request):
    return {"status": "ok"}

@app.get("/auth/v1/callback")
async def callback(request):
    return {"status": "ok"}

@app.get("/auth/v1/profile", auth_required=True)
async def get_profile(request):
    return {"status": "ok"}

@app.post("/auth/v1/profile", auth_required=True)
async def create_profile(request):
    return {"status": "ok"}

@app.patch("/auth/v1/profile", auth_required=True)
async def update_profile(request):
    return {"status": "ok"}
Screenshot_2024-10-12_at_2 08 07_PM

Steps to Reproduce

You can run this source file - https://github.com/Rohithzr/robyn-template/blob/main/standalone.py

git clone https://github.com/Rohithzr/robyn-template
pip install robyn
python standalone.py

Your operating system

MacOS

Your Python version (python --version)

3.11

Your Robyn version

latest

Additional Info

No response

sansyrox commented 1 week ago

Thanks for opening this @Rohithzr 😄

I will have a look soon 👍

sansyrox commented 1 week ago

@VishnuSanal , could you have a look at this?