Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix registering partials as view functions #2730

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Version 1.0.1

unreleased

- Fix registering partials (with no ``__name__``) as view functions

Version 1.0
-----------
Expand Down
2 changes: 1 addition & 1 deletion flask/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:license: BSD, see LICENSE for more details.
"""

import functools
import pytest

import flask
Expand Down Expand Up @@ -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'
Expand Down