Skip to content
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

SQLAlchemy db.create_all() causing errors #11

Closed
rsyring opened this issue Jun 11, 2015 · 2 comments
Closed

SQLAlchemy db.create_all() causing errors #11

rsyring opened this issue Jun 11, 2015 · 2 comments

Comments

@rsyring
Copy link

rsyring commented Jun 11, 2015

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:

  1. Just remove the call to db.create_all(); or
  2. 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.

@mcrowson

This comment was marked as outdated.

@Lxstr
Copy link
Contributor

Lxstr commented Feb 25, 2024

Fixed since 0.6.0

@Lxstr Lxstr closed this as completed Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants