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

Parameter types are broken when using <something:path> #72

Open
andreymal opened this issue Jun 20, 2023 · 0 comments
Open

Parameter types are broken when using <something:path> #72

andreymal opened this issue Jun 20, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@andreymal
Copy link

from sanic import Sanic
from sanic.response import text

app = Sanic("MyHelloWorldApp")

@app.get("/<id:int>/<subpath:path>")
async def hello_world(request, id, subpath):
    return text(str(type(id)))

Expected response is <class 'int'>, but actual response is <class 'str'>.

Same with <id:float> or <id:uuid>.

When using <id:ymd>, it throws an error:

[2023-06-20 20:15:55 +0300] [3355801] [ERROR] Invalid matching pattern ([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))
Traceback (most recent call last):
  File "lib/python3.8/site-packages/sanic/worker/serve.py", line 117, in worker_serve
    return _serve_http_1(
  File "lib/python3.8/site-packages/sanic/server/runners.py", line 224, in _serve_http_1
    loop.run_until_complete(app._startup())
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "lib/python3.8/site-packages/sanic/app.py", line 1580, in _startup
    self.finalize()
  File "lib/python3.8/site-packages/sanic/app.py", line 1551, in finalize
    self.router.finalize()
  File "lib/python3.8/site-packages/sanic/router.py", line 202, in finalize
    super().finalize(*args, **kwargs)
  File "lib/python3.8/site-packages/sanic_routing/router.py", line 329, in finalize
    route.finalize()
  File "lib/python3.8/site-packages/sanic_routing/route.py", line 280, in finalize
    self._compile_regex()
  File "lib/python3.8/site-packages/sanic_routing/route.py", line 267, in _compile_regex
    raise InvalidUsage(f"Invalid matching pattern {pattern}")
sanic_routing.exceptions.InvalidUsage: Invalid matching pattern ([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))
@ahopkins ahopkins added the bug Something isn't working label Jun 21, 2023
@ahopkins ahopkins self-assigned this Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants