Skip to content

Commit

Permalink
Fix initializing session in database
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed May 18, 2023
1 parent 98fd019 commit 976d508
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions resultsdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def create_app(config_obj=None):

db.init_app(app)

app.config["SESSION_SQLALCHEMY"] = db
app.server_session = Session(app)
init_session(app)

register_handlers(app)

Expand Down Expand Up @@ -187,6 +186,19 @@ def not_found(error):
return jsonify({"message": "Not found"}), 404


def init_session(app):
app.config["SESSION_SQLALCHEMY"] = db
app.server_session = Session(app)
if app.config["SESSION_TYPE"] == "sqlalchemy":
import sqlalchemy

with app.app_context():
inspect = sqlalchemy.inspect(db.engine)
table = app.config["SESSION_SQLALCHEMY_TABLE"]
if not inspect.has_table(table):
db.create_all()


def enable_oidc(app):
with open(app.config["OIDC_CLIENT_SECRETS"]) as client_secrets_file:
client_secrets = json.load(client_secrets_file)
Expand Down
1 change: 1 addition & 0 deletions resultsdb/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Config(object):
PERMANENT_SESSION_LIFETIME = 300

SESSION_TYPE = "sqlalchemy"
SESSION_SQLALCHEMY_TABLE = "sessions"
SESSION_PERMANENT = True
SESSION_USE_SIGNER = True
SESSION_COOKIE_SECURE = True
Expand Down

0 comments on commit 976d508

Please sign in to comment.