From 3cfb0952511b9a791fb0427abc10528e34b5c198 Mon Sep 17 00:00:00 2001 From: asriniva <69502+asriniva@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:51:19 -0700 Subject: [PATCH 1/2] Move backwards-compatible logic before function source load --- src/functions_framework/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/functions_framework/__init__.py b/src/functions_framework/__init__.py index 246dcbb2..9b5f97f3 100644 --- a/src/functions_framework/__init__.py +++ b/src/functions_framework/__init__.py @@ -232,11 +232,7 @@ def create_app(target=None, source=None, signature_type=None): global errorhandler errorhandler = app.errorhandler - # 6. Execute the module, within the application context - with app.app_context(): - spec.loader.exec_module(source_module) - - # Handle legacy GCF Python 3.7 behavior + # 6. Handle legacy GCF Python 3.7 behavior if os.environ.get("ENTRY_POINT"): os.environ["FUNCTION_TRIGGER_TYPE"] = signature_type os.environ["FUNCTION_NAME"] = os.environ.get("K_SERVICE", target) @@ -254,6 +250,10 @@ def handle_none(rv): sys.stderr = _LoggingHandler("ERROR", sys.stderr) setup_logging() + # 7. Execute the module, within the application context + with app.app_context(): + spec.loader.exec_module(source_module) + # Extract the target function from the source file if not hasattr(source_module, target): raise MissingTargetException( From 5ae921a419255e0226abd2a5ec24da919be6c16c Mon Sep 17 00:00:00 2001 From: asriniva <69502+asriniva@users.noreply.github.com> Date: Mon, 11 Oct 2021 14:11:54 -0700 Subject: [PATCH 2/2] Fix formatting --- src/functions_framework/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions_framework/__init__.py b/src/functions_framework/__init__.py index 9b5f97f3..74329dba 100644 --- a/src/functions_framework/__init__.py +++ b/src/functions_framework/__init__.py @@ -232,7 +232,7 @@ def create_app(target=None, source=None, signature_type=None): global errorhandler errorhandler = app.errorhandler - # 6. Handle legacy GCF Python 3.7 behavior + # 6. Handle legacy GCF Python 3.7 behavior if os.environ.get("ENTRY_POINT"): os.environ["FUNCTION_TRIGGER_TYPE"] = signature_type os.environ["FUNCTION_NAME"] = os.environ.get("K_SERVICE", target)