Browse Source

Fix registering partials as view functions

pull/2730/head
ThiefMaster 7 years ago
parent
commit
6663bf1f7d
  1. 1
      CHANGES.rst
  2. 2
      flask/blueprints.py
  3. 3
      tests/test_blueprints.py

1
CHANGES.rst

@ -9,6 +9,7 @@ Version 1.0.1
unreleased
- Fix registering partials (with no ``__name__``) as view functions
Version 1.0
-----------

2
flask/blueprints.py

@ -201,7 +201,7 @@ class Blueprint(_PackageBoundObject):
"""
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))

3
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 test_route_decorator_custom_endpoint_with_dots(app, client):
)
)
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'

Loading…
Cancel
Save