From 0bc656014c98fb7e4745a07a53e410ab3be90a3e Mon Sep 17 00:00:00 2001 From: Flavio Garcia Date: Sat, 20 Apr 2024 23:59:13 -0400 Subject: [PATCH] refactor(data): move islolation_level to the data source root Now the islolation_level configuration item will be at the data source root level Fixes: #447 --- examples/testapp/app.py | 4 ++-- examples/testapp/services.py | 2 -- firenado/data.py | 8 ++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/testapp/app.py b/examples/testapp/app.py index 5efc48d..6f01241 100644 --- a/examples/testapp/app.py +++ b/examples/testapp/app.py @@ -68,10 +68,10 @@ def initialize(self): data_source_conf = { 'connector': "sqlalchemy", 'url': "mysql+pymysql://root@localhost:3306/test", + # 'isolation_level': 'REPEATABLE READ', 'pool': { 'size': 10, 'max_overflow': 10, - # 'isolation_level': 'REPEATABLE READ', # 'pool_recycle': 400 } } @@ -85,7 +85,7 @@ def initialize(self): def install(self): """ Installing test database """ - from firenado.util.sqlalchemy_util import Base + from testapp.models import Base print('Installing Testapp App...') print('Creating App ...') engine = self.application.get_data_source( diff --git a/examples/testapp/services.py b/examples/testapp/services.py index b6e794f..9de8ada 100644 --- a/examples/testapp/services.py +++ b/examples/testapp/services.py @@ -72,5 +72,3 @@ def is_valid(self, username, password): if user.password == password_digest(password): return True return False - - diff --git a/firenado/data.py b/firenado/data.py index 0251979..002673b 100644 --- a/firenado/data.py +++ b/firenado/data.py @@ -161,7 +161,6 @@ def configure(self, name, conf): # We will set the isolation level to READ UNCOMMITTED by default # to avoid the "cache" effect sqlalchemy has without this option. # Solution from: http://bit.ly/2bDq0Nv - # TODO: Get the isolation level from data source conf engine_params = { 'isolation_level': "READ UNCOMMITTED" } @@ -176,15 +175,16 @@ def configure(self, name, conf): if conf['future']: engine_params['future'] = True + if "isolation_level" in conf: + if conf['isolation_level']: + engine_params['isolation_level'] = conf['isolation_level'] + if "pool" in conf: if "class" in conf['pool']: engine_params['pool_class'] = conf['pool']['class'] if isinstance(engine_params['pool_class'], str): engine_params['pool_class'] = config.get_from_string( engine_params['pool_class']) - if "isolation_level" in conf['pool']: - engine_params['isolation_level'] = conf['pool'][ - 'isolation_level'] if "max_overflow" in conf['pool']: engine_params['max_overflow'] = conf['pool']['max_overflow'] if "pool_recycle" in conf['pool']: