From 12706703eb77eaafef9c79ba60665a3d5a139d58 Mon Sep 17 00:00:00 2001 From: Sander van Leeuwen Date: Thu, 24 Mar 2022 12:11:17 +0100 Subject: [PATCH 1/2] fix: Add functools.wraps decorator (#178) To make sure function attributes are copied to `_http_view_func_wrapper` --- src/functions_framework/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions_framework/__init__.py b/src/functions_framework/__init__.py index 46c8882b..5d18d2ab 100644 --- a/src/functions_framework/__init__.py +++ b/src/functions_framework/__init__.py @@ -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()) From 7d9f32d8577e06a17fa2c51bd1f7dc6d1830aafe Mon Sep 17 00:00:00 2001 From: Sander van Leeuwen Date: Fri, 1 Apr 2022 12:16:40 +0200 Subject: [PATCH 2/2] fix: Add test for _http_view_func_wrapper attribute (#178) --- tests/test_view_functions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_view_functions.py b/tests/test_view_functions.py index 219313f9..3af3abcd 100644 --- a/tests/test_view_functions.py +++ b/tests/test_view_functions.py @@ -31,6 +31,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 = {