Skip to content

Adding the same route twice will silently fail, should raise an exception instead #3037

@502E532E

Description

@502E532E

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions