Skip to content

Commit d5651bb

Browse files
asrinivadi
andauthored
fix: Move backwards-compatible logic before function source load (#152)
* Move backwards-compatible logic before function source load * Fix formatting Co-authored-by: Dustin Ingram <[email protected]>
1 parent f0749e0 commit d5651bb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/functions_framework/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,7 @@ def create_app(target=None, source=None, signature_type=None):
232232
global errorhandler
233233
errorhandler = app.errorhandler
234234

235-
# 6. Execute the module, within the application context
236-
with app.app_context():
237-
spec.loader.exec_module(source_module)
238-
239-
# Handle legacy GCF Python 3.7 behavior
235+
# 6. Handle legacy GCF Python 3.7 behavior
240236
if os.environ.get("ENTRY_POINT"):
241237
os.environ["FUNCTION_TRIGGER_TYPE"] = signature_type
242238
os.environ["FUNCTION_NAME"] = os.environ.get("K_SERVICE", target)
@@ -254,6 +250,10 @@ def handle_none(rv):
254250
sys.stderr = _LoggingHandler("ERROR", sys.stderr)
255251
setup_logging()
256252

253+
# 7. Execute the module, within the application context
254+
with app.app_context():
255+
spec.loader.exec_module(source_module)
256+
257257
# Extract the target function from the source file
258258
if not hasattr(source_module, target):
259259
raise MissingTargetException(

0 commit comments

Comments
 (0)