Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Raise exceptions if a function is overridden by a new endpoint. This …

…fixes #570
  • Loading branch information...
commit 661ee54bc2bc1ea0763ac9c226f8e14bb0beb5b1 1 parent e2b3f07
@mitsuhiko authored
View
5 flask/app.py
@@ -942,8 +942,13 @@ 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:
+ old_func = self.view_functions.get(endpoint)
+ if old_func is not None and old_func is not view_func:
+ raise AssertionError('View function mapping is overwriting an '
+ 'existing endpoint function: %s' % endpoint)
self.view_functions[endpoint] = view_func
def route(self, rule, **options):
View
2  flask/testsuite/basic.py
@@ -387,7 +387,7 @@ def test_filters():
return ''
@app.route('/test_filters_without_returning_categories/')
- def test_filters():
+ def test_filters2():
messages = flask.get_flashed_messages(category_filter=['message', 'warning'])
self.assert_equal(len(messages), 2)
self.assert_equal(messages[0], u'Hello World')
View
17 flask/testsuite/views.py
@@ -145,6 +145,23 @@ 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'))
+
+ with self.assert_raises(AssertionError):
+ 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()
Please sign in to comment.
Something went wrong with that request. Please try again.