Skip to content

Commit

Permalink
fix: Add functools.wraps decorator (#179)
Browse files Browse the repository at this point in the history
* fix: Add functools.wraps decorator (#178)

To make sure function attributes are copied to `_http_view_func_wrapper`

Co-authored-by: Annie Fu <16651409+anniefu@users.noreply.github.com>
  • Loading branch information
svleeuwen and anniefu authored May 10, 2022
1 parent 6c9ce8c commit f2285f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/functions_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def setup_logging():


def _http_view_func_wrapper(function, request):
@functools.wraps(function)
def view_func(path):
return function(request._get_current_object())

Expand Down
11 changes: 11 additions & 0 deletions tests/test_view_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ def test_http_view_func_wrapper():
assert function.calls == [pretend.call(request_object)]


def test_http_view_func_wrapper_attribute_copied():
def function(_):
pass

function.attribute = "foo"
view_func = functions_framework._http_view_func_wrapper(function, pretend.stub())

assert view_func.__name__ == "function"
assert view_func.attribute == "foo"


def test_event_view_func_wrapper(monkeypatch):
data = pretend.stub()
json = {
Expand Down

0 comments on commit f2285f9

Please sign in to comment.