-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing Flask app context results in RuntimeError: Working outside of application context.
#75
Comments
Hi @mayanksha thanks for filing an issue. I'd say this isn't a bug, but you also aren't really doing anything wrong here: you're just relying on an undefined / unofficial implementation detail. We don't explicitly document that That said, given that this works when deployed, I think this is a trivial enough change that we can make an update to the framework to maintain parity. Can you try installing the branch from #76 locally and confirm that it works for you? You should be able to do that with:
|
I tested these changes and I can confirm that it works as expected. Thanks! :-) |
HI @mayanksha @di
Please share a solution if you have. |
I was trying to include from flask import current_app as app
from flask_compress import Compress
Compress(app) |
Hi,
I was trying to deploy some Google Cloud Functions today and found out about this wonderful project to test the functions locally. I can't thank you enough for this project, since it saves a lot of time (deploying is very time consuming, and being able to test it locally is a big relief).
I've created a minimum viable example that can help to reproduce the error. The same example works wonderfully when deployed as a Google Cloud Function, but it fails with an error when run with
functions-framework
. The error is as follows (I'm using python 3.7 to create a virtual env and testing within that):The Example is as follows (2 files):
requirements.txt
filemain.py
fileThe issue seems to be in the
__init__.py
file where we create an instance of the Flask app (https://github.com/GoogleCloudPlatform/functions-framework-python/blob/master/src/functions_framework/__init__.py#L154-L175). I'm not great at python, but it looks to me as if the module is imported before the Flask app context is even created. So, if I move theapp = flask.Flask(target, template_folder=template_folder)
before I import the source module, I can successfully runfunctions-framework
without an errors.In terms of code, something like this (i'm not sure if I'm doing it correctly, so please bear with me):
Is it a bug, or am I doing something wrong here?
The text was updated successfully, but these errors were encountered: