Skip to content

Commit

Permalink
CH-109 fix flask-sql, tweak dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
filippomc committed Jan 16, 2024
1 parent 9b59a1d commit ec25adb
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
6 changes: 5 additions & 1 deletion applications/common/server/common/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
from cloudharness import log
from flask_cors import CORS
from common.repository.db import open_db
from common.controllers.sentry_controller import global_dsn



def init_fn(app):
log.info("initializing database from app")
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
open_db(app)
if not global_dsn:
open_db(app)

app = init_flask(init_app_fn=init_fn)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from cloudharness.utils.env import get_sentry_service_cluster_address
from common.repository.sentry import get_token, get_dsn, SentryProjectNotFound


try:
global_dsn = os.environ.get("SENTRY_DSN", "")
if len(global_dsn) < 1:
global_dsn = None
except:
global_dsn = None


def getdsn(appname): # noqa: E501
"""
Gets the Sentry DSN for a given application or returns the global dsn when set
Expand Down
8 changes: 6 additions & 2 deletions applications/common/server/common/repository/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask_sqlalchemy import SQLAlchemy
from cloudharness import log

db = None

Expand All @@ -12,6 +13,9 @@ def get_db():

def open_db(app):
global db
if not db:
db = SQLAlchemy(app)
try:
if not db:
db = SQLAlchemy(app)
except Exception as e:
log.exception("Sentry database cannot be initialized")
return db
6 changes: 3 additions & 3 deletions applications/common/server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ connexion[swagger-ui]==2.14.2
swagger-ui-bundle >= 0.0.2
python_dateutil >= 2.6.0
setuptools >= 21.0.0
Flask >= 2.1.0
flask_sqlalchemy==2.4.4
sqlalchemy
Flask<3.0.0
flask_sqlalchemy==3.0.2
sqlalchemy<2.0.0
2 changes: 1 addition & 1 deletion applications/samples/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ connexion[swagger-ui]==2.14.2
swagger-ui-bundle >= 0.0.2
python_dateutil >= 2.6.0
setuptools >= 21.0.0
Flask >= 2.1.0
Flask<3.0.0
2 changes: 1 addition & 1 deletion applications/volumemanager/server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ connexion[swagger-ui]==2.14.2
swagger-ui-bundle >= 0.0.2
python_dateutil >= 2.6.0
setuptools >= 21.0.0
Flask >= 2.1.0
Flask<3.0.0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
connexion[swagger-ui]==2.14.2
Flask>=2.1.0
Flask<3.0.0
Flask-Cors>=4.0.0
gunicorn>=21.2.0
itsdangerous>=2.1.2
Expand Down

0 comments on commit ec25adb

Please sign in to comment.