From 6663bf1f7d5a43633e6434a5dd8ea8f8eccdd616 Mon Sep 17 00:00:00 2001 From: ThiefMaster Date: Fri, 27 Apr 2018 13:38:35 +0200 Subject: [PATCH] Fix registering partials as view functions --- CHANGES.rst | 1 + flask/blueprints.py | 2 +- tests/test_blueprints.py | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index c6415447b7..9ad5bb36a5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,7 @@ Version 1.0.1 unreleased +- Fix registering partials (with no ``__name__``) as view functions Version 1.0 ----------- diff --git a/flask/blueprints.py b/flask/blueprints.py index d633685fbd..0a6ccfb76e 100644 --- a/flask/blueprints.py +++ b/flask/blueprints.py @@ -201,7 +201,7 @@ def add_url_rule(self, rule, endpoint=None, view_func=None, **options): """ if endpoint: assert '.' not in endpoint, "Blueprint endpoints should not contain dots" - if view_func: + if view_func and hasattr(view_func, '__name__'): assert '.' not in view_func.__name__, "Blueprint view function name should not contain dots" self.record(lambda s: s.add_url_rule(rule, endpoint, view_func, **options)) diff --git a/tests/test_blueprints.py b/tests/test_blueprints.py index 7984a815e6..a26312416e 100644 --- a/tests/test_blueprints.py +++ b/tests/test_blueprints.py @@ -9,6 +9,7 @@ :license: BSD, see LICENSE for more details. """ +import functools import pytest import flask @@ -382,6 +383,8 @@ def foo_foo_foo(): ) ) + bp.add_url_rule('/bar/456', endpoint='foofoofoo', view_func=functools.partial(foo_foo_foo)) + app.register_blueprint(bp, url_prefix='/py') assert client.get('/py/foo').data == b'bp.foo'