I have a route like this,
which works fine in sanic 20.12
@bp.route('/tiff/<id>.tiff', name='img_tiff')
but fails on 21 with
File "/usr/local/miniconda3/envs/web39/lib/python3.9/site-packages/sanic/app.py", line 421, in blueprint
blueprint.register(self, options)
File "/usr/local/miniconda3/envs/web39/lib/python3.9/site-packages/sanic/blueprints.py", line 227, in register
route = app._apply_route(apply_route)
File "/usr/local/miniconda3/envs/web39/lib/python3.9/site-packages/sanic/app.py", line 335, in _apply_route
routes = self.router.add(**params)
File "/usr/local/miniconda3/envs/web39/lib/python3.9/site-packages/sanic/router.py", line 128, in add
route = super().add(**params) # type: ignore
File "/usr/local/miniconda3/envs/web39/lib/python3.9/site-packages/sanic_routing/router.py", line 133, in add
path = parts_to_path(
File "/usr/local/miniconda3/envs/web39/lib/python3.9/site-packages/sanic_routing/utils.py", line 80, in parts_to_path
raise ValueError(f"Invalid declaration: {part}")
ValueError: Invalid declaration: <id>.tiff
removing the extension avoids the error:
@bp.route('/tiff/<id>', name='img_tiff')
After some more checks it seems in 20.12 it doesn’t worked as intended, as the text after the variable was silently ignored, and my code used an id with was the real filename, so two errors canceling each other…
My Question:
Is it possible to create a route like my original with sanic 21?
Is this behaviour intentional, as only a complete path segment (text between two “/)” can be an argument for a route or should it work more like a pattern or regex like i used it?
The Router changed in 21, from regex to objects, which could change a lot here.