Skip to content

Commit cdd9c17

Browse files
committed
Execute the source module w/in the app context
1 parent 0ef9bcd commit cdd9c17

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/functions_framework/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,14 @@ def create_app(target=None, source=None, signature_type=None):
168168
# 4. Add the module to sys.modules
169169
sys.modules[name] = source_module
170170

171-
# 5. Execute the module
172-
spec.loader.exec_module(source_module)
173-
171+
# 5. Create the application
174172
app = flask.Flask(target, template_folder=template_folder)
175173
app.config["MAX_CONTENT_LENGTH"] = MAX_CONTENT_LENGTH
176174

175+
# 6. Execute the module, within the application context
176+
with app.app_context():
177+
spec.loader.exec_module(source_module)
178+
177179
# Extract the target function from the source file
178180
try:
179181
function = getattr(source_module, target)

0 commit comments

Comments
 (0)