From 5c641e8c8db0616461aa12b87c233887c87c3a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Mon, 17 Oct 2022 19:51:39 +0200 Subject: [PATCH] fix flask-marshmallow factory pattern issue ma.init_app(app) replace DummySession() by db.session but its too late, schemas have already been created, so replace it as soon as ma have been initialized. https://github.com/marshmallow-code/flask-marshmallow/issues/44 https://github.com/marshmallow-code/flask-marshmallow/issues/74 https://github.com/marshmallow-code/flask-marshmallow/pull/111 --- backend/geonature/utils/env.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/geonature/utils/env.py b/backend/geonature/utils/env.py index bdd10a0a9a..527d8e091f 100644 --- a/backend/geonature/utils/env.py +++ b/backend/geonature/utils/env.py @@ -33,6 +33,8 @@ DB = db = SQLAlchemy() os.environ["FLASK_MARSHMALLOW"] = "geonature.utils.env.ma" MA = ma = Marshmallow() +ma.SQLAlchemySchema.OPTIONS_CLASS.session = db.session +ma.SQLAlchemyAutoSchema.OPTIONS_CLASS.session = db.session os.environ["FLASK_MIGRATE"] = "geonature.utils.env.migrate" migrate = Migrate()