SQLAlchemy db.create_all() causing errors
The use of self.db.create_all() in SqlAlchemySessionInterface is causing me some problems:
https://github.com/fengsp/flask-session/blob/master/flask_session/sessions.py#L458
When using two-step invocation, there is no guarantee of an app context available when session.init_app() is run. The call to db.create_all() results in an error like:
RuntimeError: application not registered on db instance and no application bound to current context
Furthermore, I don't think it's the job of Flask-Session to call this method anyway. If the table needs to be created, IMO that needs to be handled by the application developer.
Suggestions:
- Just remove the call to
db.create_all(); or - Add a configuration option that would allow us to skip this method being called.
If you decide on option 2 above, then IMO the call to db.create_all() should still be replaced by code that only creates the session table. Based on these docs:
http://docs.sqlalchemy.org/en/latest/core/metadata.html
That would look something like the following for SqlAlchemySessionInterface.__init__():
class Session(self.db.model):
...
if create_session_table:
Session.table.create(db.engine)
I'd be happy to create a PR if you are interested.
This issue was moved to mcrowson/flask-session#9
Fixed since 0.6.0