Skip to content

Commit

Permalink
Execute the source module w/in the app context
Browse files Browse the repository at this point in the history
  • Loading branch information
di committed Jul 31, 2020
1 parent 0ef9bcd commit cdd9c17
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/functions_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cdd9c17

Please sign in to comment.