sanic-org / sanic-routing

Internal handler routing for Sanic beginning with v21.3.

Home Page:https://sanicframework.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parts_to_path, raises exception for part with multiple parameters without type hint

riokuu opened this issue · comments

import sanic_routing.utils as sru
sru.path_to_parts('/asd/<int1>,<int2>')
('asd', '<int1>,<int2>')
sru.parts_to_path(sru.path_to_parts('/asd/<int1>,<int2>'))
Traceback (most recent call last):
  File "/srv/git/sensors-server/venv/lib/python3.9/site-packages/sanic_routing/utils.py", line 75, in parts_to_path
    if match.group(2):
AttributeError: 'NoneType' object has no attribute 'group'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/srv/git/sensors-server/venv/lib/python3.9/site-packages/sanic_routing/utils.py", line 83, in parts_to_path
    if match.group(2):
AttributeError: 'NoneType' object has no attribute 'group'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.9/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/srv/git/sensors-server/venv/lib/python3.9/site-packages/sanic_routing/utils.py", line 93, in parts_to_path
    raise InvalidUsage(f"Invalid declaration: {part}")
sanic_routing.exceptions.InvalidUsage: Invalid declaration: <int1>,<int2>

Correct. That is an invalid path. Multiple matches per segment is not supported. You should use a custom regex matcher.

https://sanic.dev/en/guide/basics/routing.html#path-parameters