Skip to content
Browse files

Issue #570: log a warning if a duplicate endpoint mapping is added.

  • Loading branch information...
1 parent 80b2689 commit 859f091d187f8491529ce39a3deb7c6cc0ab4df6 @YoavShapira committed Sep 18, 2012
Showing with 25 additions and 1 deletion.
  1. +6 −1 flask/app.py
  2. +19 −0 flask/testsuite/views.py
View
7 flask/app.py
@@ -942,10 +942,15 @@ def index():
rule = self.url_rule_class(rule, methods=methods, **options)
rule.provide_automatic_options = provide_automatic_options
+
self.url_map.add(rule)
if view_func is not None:
+ # Issue 570: warn if overwriting an existing rule.
+ # https://github.com/mitsuhiko/flask/issues/570
+ if endpoint in self.view_functions:
+ self.logger.warn("View function mapping is overwriting an existing endpoint mapping: %s" % str(endpoint))
self.view_functions[endpoint] = view_func
-
+
def route(self, rule, **options):
"""A decorator that is used to register a view function for a
given URL rule. This does the same thing as :meth:`add_url_rule`
View
19 flask/testsuite/views.py
@@ -145,6 +145,25 @@ def head(self):
self.assert_equal(rv.data, '')
self.assert_equal(rv.headers['X-Method'], 'HEAD')
+ def test_endpoint_override(self):
+ app = flask.Flask(__name__)
+ app.debug = True
+
+ class Index(flask.views.View):
+ methods = ['GET', 'POST']
+ def dispatch_request(self):
+ return flask.request.method
+
+ app.add_url_rule('/', view_func=Index.as_view('index'))
+
+ # Issue 570: log a warning if overwriting an endpoint
+ # https://github.com/mitsuhiko/flask/issues/570
+ app.logger.info("We are expecting a WARNING logged below due to duplicate endpoint mapping.")
+ app.add_url_rule('/', view_func=Index.as_view('index'))
+
+ # But these tests should still pass. We just log a warning.
+ self.common_test(app)
+
def suite():
suite = unittest.TestSuite()

0 comments on commit 859f091

Please sign in to comment.
Something went wrong with that request. Please try again.