From cdd9c17f54ca7b1a2a16d7a8718d3fee53c4d72a Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Thu, 30 Jul 2020 20:10:21 -0500 Subject: [PATCH] Execute the source module w/in the app context --- src/functions_framework/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/functions_framework/__init__.py b/src/functions_framework/__init__.py index b7f38290..86e940cf 100644 --- a/src/functions_framework/__init__.py +++ b/src/functions_framework/__init__.py @@ -168,12 +168,14 @@ def create_app(target=None, source=None, signature_type=None): # 4. Add the module to sys.modules sys.modules[name] = source_module - # 5. Execute the module - spec.loader.exec_module(source_module) - + # 5. Create the application app = flask.Flask(target, template_folder=template_folder) app.config["MAX_CONTENT_LENGTH"] = MAX_CONTENT_LENGTH + # 6. 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 try: function = getattr(source_module, target)