dcrosta/flask-pymongo — Issue #11: Failing to instantiate PyMongo objects from @app.before_request
Author: delinhabit
Created: 2012-01-07 10:33:22+00:00
State: open

Hey,

I'm not sure if this is because I'm doing something wrong or there is actually an issue. I'm creating the Flask application object from a factory function located in the application.py module. In the views I try to use g.mongo.db.... to access the database operations. When I'm trying to put the PyMongo object on the flask g object it throws me an exception (see below)

# applications.py
def create(extra_config=None):
app = Flask(__name__)

app.config.from_object('authz.default_settings')
app.config.from_envvar('AUTHZ_SETTINGS_OVERRIDE', silent=True)

if extra_config:
app.config.from_object(extra_config)

from views.api import api_endpoints
app.register_blueprint(api_endpoints, url_prefix='/api')

return app

# web.py
from authz import application
app = application.create()

@app.before_request
def before_request():
g.mongo = PyMongo(app)

On request the following exception is raised: http://paste.pocoo.org/show/q0lUlcRBREC1AqtjBxqm/
What am I doing wrong here?