Skip to content

Support overwriting a route of blueprint from copy #2554

@Tpinion

Description

@Tpinion

Feture Description
I want to overwrite the implement of route partially when they belong to different version blueprint, and it raises sanic_routing.exceptions.RouteExists.
Sample Code

from sanic import Blueprint
from sanic.response import json
from sanic import Sanic

app = Sanic('test')

bpv1 = Blueprint('bpv1', version=1)

@bpv1.route('/hello')
async def root(request):
    return json('hello v1')

app.blueprint(bpv1)

bpv2 = bpv1.copy('bpv2', version=2)

@bpv2.route('/hello')
async def root(request):
    return json('hello v2')

app.blueprint(bpv2)

Current Solution
I get this solution from forum and i was encouraged to post new a feature request based on it~

bpv2 = bpv1.copy("bpv2", version=2)

bpv2._future_routes = {
    route for route in bpv2._future_routes if route.uri != "/hello"
}


@bpv2.route("/hello")
async def root2(request):
    return json("hello v2")

Web Link
https://community.sanicframework.org/t/how-to-overwrite-a-route-when-using-blueprint-copy/1067

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions