From ec25adbd55c7778a3425af837aff5c548571d735 Mon Sep 17 00:00:00 2001 From: Filippo Ledda Date: Tue, 16 Jan 2024 18:55:24 +0100 Subject: [PATCH] CH-109 fix flask-sql, tweak dependencies --- applications/common/server/common/__main__.py | 6 +++++- .../common/server/common/controllers/sentry_controller.py | 2 +- applications/common/server/common/repository/db.py | 8 ++++++-- applications/common/server/requirements.txt | 6 +++--- applications/samples/backend/requirements.txt | 2 +- applications/volumemanager/server/requirements.txt | 2 +- .../common-images/cloudharness-flask/requirements.txt | 2 +- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/applications/common/server/common/__main__.py b/applications/common/server/common/__main__.py index 32256869..4bd6ef17 100644 --- a/applications/common/server/common/__main__.py +++ b/applications/common/server/common/__main__.py @@ -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) diff --git a/applications/common/server/common/controllers/sentry_controller.py b/applications/common/server/common/controllers/sentry_controller.py index 44f15d5d..1daee66f 100644 --- a/applications/common/server/common/controllers/sentry_controller.py +++ b/applications/common/server/common/controllers/sentry_controller.py @@ -5,6 +5,7 @@ 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: @@ -12,7 +13,6 @@ except: global_dsn = None - def getdsn(appname): # noqa: E501 """ Gets the Sentry DSN for a given application or returns the global dsn when set diff --git a/applications/common/server/common/repository/db.py b/applications/common/server/common/repository/db.py index f0eba317..8433b3a9 100644 --- a/applications/common/server/common/repository/db.py +++ b/applications/common/server/common/repository/db.py @@ -1,4 +1,5 @@ from flask_sqlalchemy import SQLAlchemy +from cloudharness import log db = None @@ -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 diff --git a/applications/common/server/requirements.txt b/applications/common/server/requirements.txt index 441a0a06..8acc510d 100644 --- a/applications/common/server/requirements.txt +++ b/applications/common/server/requirements.txt @@ -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 \ No newline at end of file +Flask<3.0.0 +flask_sqlalchemy==3.0.2 +sqlalchemy<2.0.0 \ No newline at end of file diff --git a/applications/samples/backend/requirements.txt b/applications/samples/backend/requirements.txt index 25d87879..b3db72c8 100644 --- a/applications/samples/backend/requirements.txt +++ b/applications/samples/backend/requirements.txt @@ -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 diff --git a/applications/volumemanager/server/requirements.txt b/applications/volumemanager/server/requirements.txt index 25d87879..b3db72c8 100644 --- a/applications/volumemanager/server/requirements.txt +++ b/applications/volumemanager/server/requirements.txt @@ -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 diff --git a/infrastructure/common-images/cloudharness-flask/requirements.txt b/infrastructure/common-images/cloudharness-flask/requirements.txt index 519bd654..b3d67d34 100644 --- a/infrastructure/common-images/cloudharness-flask/requirements.txt +++ b/infrastructure/common-images/cloudharness-flask/requirements.txt @@ -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