Flask does not warn about adding the same route twice. It will continue to use the view function from the first registration and just silently fail on a second registration.
Desired behavior:
Similar to adding the same endpoint twice, some exception should be raised.
import flask
app = flask.Flask(__name__)
@app.route("/test")
def myfunc1():
return "myfunc1"
@app.route("/test") # This should raise an exception
def myfunc2():
return "myfunc2"
app.add_url_rule("/test", "my test endpoint", lambda: "myfunc3") # This, too
cli = app.test_client()
response = cli.get("/test")
data = response.get_data(True)
print(data) # Prints "myfunc1"
Environment:
- Python version: 3.13.2
- Flask version: 3.1.0