Issue With Conflicting Path Parameters #825
-
Hello, I didn't want to submit an issue as I wasn't sure if this was an issue on my end and I couldn't find anything related in discussions nor issues. I keep getting the following error:
with the following controller:
Based on https://starlite-api.github.io/starlite/usage/1-routing/3-controllers/?h=contr, this should be fine as the path + http method combination is unique for both of them, yet each time I get that same error. When I keep the delete route by itself, it works, and vice versa for the post route. Am I doing something incorrectly here? I have been able to fix it by adding another path level (e.g. changing the delete path to |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
Have confirmed and created an issue from the discussion, cheers! |
Beta Was this translation helpful? Give feedback.
-
so, we should fix the docs - this is not support currently. |
Beta Was this translation helpful? Give feedback.
-
I was faced with a similar issue today, the path parameter types were the same, but the names differed. Unfortunately there's no ImproperlyConfiguredException when you start the app, you just get a somewhat confusing 400 response: {
"status_code": 400,
"detail": "Missing required parameter foo for url http://127.0.0.1:8000/f/foo"
} Here's the example for this: from starlite import Starlite, get
@get("/{foo:str}/foo")
def foo_handler(foo: str) -> str:
return foo
@get("/{bar:str}/bar")
def bar_handler(bar: str) -> str:
return bar
app = Starlite(route_handlers=[foo_handler, bar_handler]) Is this related or should I open a separate issue for this? |
Beta Was this translation helpful? Give feedback.
-
The issue you're having is somewhat different. We can potentially support this. The difference is between having two different parameters for the same exact path. These paths represent different nodes: from starlite import Starlite, get
@get("/{foo:str}/foo")
def foo_handler(foo: str) -> str:
return foo
@get("/{bar:str}/bar")
def bar_handler(bar: str) -> str:
return bar If we parse path params after we resolve the complete path, we can support this. This will force us to return not found slighlty later, and is in this regard less efficent, but otherwise it's fine. This though we cannot support without incurring a serious performance penalty or doing some complex rework of routing. What's the problem? We cannot know which parameter is in fact correct from this: from starlite import Starlite, get
@get("/{foo:float}/")
def foo_handler(foo: str) -> str:
return foo
@get("/{bar:str}/")
def bar_handler(bar: str) -> str:
return bar If the value is a float, we should have one handler. If it's a string, we should resolve to another. But a path parameter is always a string. How can we know that the intention there was to be a string or float? We can't. Hence this problem. |
Beta Was this translation helpful? Give feedback.
Have confirmed and created an issue from the discussion, cheers!