Comments (4)
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 from flask import current_app
should work, and it's not officially supported.
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:
$ pip install git+https://github.com/googlecloudplatform/functions-framework-python.git@fix/75
from functions-framework-python.
I tested these changes and I can confirm that it works as expected. Thanks! :-)
from functions-framework-python.
HI @mayanksha @di
I'm trying to do same using latest version of functions-framework but having another error on db = SQLAlchemy(app)
from flask import jsonify
import functions_framework
from flask import current_app as app
from flask_sqlalchemy import SQLAlchemy
def setup_context():
app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
return db
with app.app_context():
db = setup_context()
@functions_framework.http
def posts_test(request):
request_json = request.get_json(silent=True)
request_args = request.args
return jsonify({'success': True})
Traceback (most recent call last):
File "/Users/dv/Library/Caches/pypoetry/virtualenvs/cloudbench-U2d1CbNl-py3.9/bin/functions-framework", line 8, in <module>
sys.exit(_cli())
File "/Users/dv/Library/Caches/pypoetry/virtualenvs/cloudbench-U2d1CbNl-py3.9/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/Users/dv/Library/Caches/pypoetry/virtualenvs/cloudbench-U2d1CbNl-py3.9/lib/python3.9/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/Users/dv/Library/Caches/pypoetry/virtualenvs/cloudbench-U2d1CbNl-py3.9/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/dv/Library/Caches/pypoetry/virtualenvs/cloudbench-U2d1CbNl-py3.9/lib/python3.9/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/Users/dv/Library/Caches/pypoetry/virtualenvs/cloudbench-U2d1CbNl-py3.9/lib/python3.9/site-packages/functions_framework/_cli.py", line 36, in _cli
app = create_app(target, source, signature_type)
File "/Users/dv/Library/Caches/pypoetry/virtualenvs/cloudbench-U2d1CbNl-py3.9/lib/python3.9/site-packages/functions_framework/__init__.py", line 353, in create_app
spec.loader.exec_module(source_module)
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/dv/Library/CloudStorage/Dropbox/cloudbench/gcloud-functions-python-postgres/main.py", line 39, in <module>
db = setup_context()
File "/Users/dv/Library/CloudStorage/Dropbox/cloudbench/gcloud-functions-python-postgres/main.py", line 34, in setup_context
db = SQLAlchemy(app)
File "/Users/dv/Library/Caches/pypoetry/virtualenvs/cloudbench-U2d1CbNl-py3.9/lib/python3.9/site-packages/flask_sqlalchemy/extension.py", line 219, in __init__
self.init_app(app)
File "/Users/dv/Library/Caches/pypoetry/virtualenvs/cloudbench-U2d1CbNl-py3.9/lib/python3.9/site-packages/flask_sqlalchemy/extension.py", line 311, in init_app
engines = self._app_engines.setdefault(app, {})
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/weakref.py", line 498, in setdefault
return self.data.setdefault(ref(key, self._remove),default)
TypeError: cannot create weak reference to 'LocalProxy' object
Please share a solution if you have.
from functions-framework-python.
I was trying to include flask-compress
to gzip all my responses, which needs access to the Flask app. Doing this seems to work:
from flask import current_app as app
from flask_compress import Compress
Compress(app)
from functions-framework-python.
Related Issues (20)
- Symbolic linking within the Source Directory to include shared local directories.
- Firebase Functions Support HOT 1
- Possibility for multiple target/signature-type pairs?
- Gunicorn 21 is out HOT 3
- Flask Celery worker raise RuntimeError(unbound_message) from None RuntimeError: Working outside of request context. HOT 2
- Add Flask 3 support HOT 2
- README.md - Flask "Request" object hyperlink is broken HOT 2
- Native support for Pydantic models for function_framework.typed
- Document functions_framework.typed
- Support for postponed annnotations
- Improve developer experience for uncaught exceptions on GCP HOT 1
- PyPi development status alpha and other classifiers HOT 1
- functions-framework and tuning gunicorn HOT 1
- enhance framework to support pull subscriptions in addition to push subscriptions with pubsub
- Memory leaks? HOT 2
- ModuleNotFoundError: No module named 'urllib3.packages.six.moves'
- Bug: Firestore AggregationQuery stuck when running locally in Docker HOT 2
- Update type check in `get_user_function` to accept Callable instead of only types.FunctionType
- Blackduck scan showing HIGH level vulnerability on v3.5.0 HOT 1
- Sudden increase in memory usage from 3.5.0 to 3.6.0 HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from functions-framework-python.