Adding allow route overwrite option in blueprint (#2716)
* Adding allow route overwrite option * Add test case for route overwriting after bp copy * Fix test * Fix * Add test case `test_bp_allow_override` * Remove conflicted future routes when overwriting is allowed * Improved test test_bp_copy_with_route_overwriting * Fix type * Fix type 2 * Add `test_bp_copy_without_route_overwriting` case * make `allow_route_overwrite` flag to be internal * Remove unwanted test case --------- Co-authored-by: Adam Hopkins <adam@amhopkins.com>
This commit is contained in:
@@ -159,7 +159,11 @@ class RouteMixin(BaseMixin, metaclass=SanicMeta):
|
||||
error_format,
|
||||
route_context,
|
||||
)
|
||||
|
||||
overwrite = getattr(self, "_allow_route_overwrite", False)
|
||||
if overwrite:
|
||||
self._future_routes = set(
|
||||
filter(lambda x: x.uri != uri, self._future_routes)
|
||||
)
|
||||
self._future_routes.add(route)
|
||||
|
||||
args = list(signature(handler).parameters.keys())
|
||||
@@ -182,7 +186,7 @@ class RouteMixin(BaseMixin, metaclass=SanicMeta):
|
||||
handler.is_stream = stream
|
||||
|
||||
if apply:
|
||||
self._apply_route(route)
|
||||
self._apply_route(route, overwrite=overwrite)
|
||||
|
||||
if static:
|
||||
return route, handler
|
||||
|
||||
Reference in New Issue
Block a user