From cc36bd0950b71cc2f08bfddd3e574f98c24795da Mon Sep 17 00:00:00 2001
From: Vincent Texier <vit@free.fr>
Date: Fri, 18 Apr 2025 11:37:33 +0200
Subject: [PATCH] [fix] fix python-sql error with qmark not set

---
 tests/adapters/repository/test_accounts.py | 29 ++++++++++++++++++++++
 tests/adapters/repository/test_indexers.py | 27 ++++++++++++++++++++
 tikka/adapters/repository/accounts.py      |  9 ++++---
 tikka/adapters/repository/indexers.py      |  5 ++--
 uv.lock                                    |  2 +-
 5 files changed, 65 insertions(+), 7 deletions(-)
 create mode 100644 tests/adapters/repository/test_accounts.py
 create mode 100644 tests/adapters/repository/test_indexers.py

diff --git a/tests/adapters/repository/test_accounts.py b/tests/adapters/repository/test_accounts.py
new file mode 100644
index 00000000..fb91068c
--- /dev/null
+++ b/tests/adapters/repository/test_accounts.py
@@ -0,0 +1,29 @@
+# Copyright 2021 Vincent Texier <vit@free.fr>
+#
+# This software is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This software is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from tikka.domains.application import Application
+from tikka.domains.entities.account import Account
+
+
+def test_accounts_list(application: Application, account: Account):
+    """
+    Test list accounts
+
+    :param application: Application instance
+    :param account: Account instance
+    :return:
+    """
+    application.accounts.add(account)
+    assert len(application.accounts.get_list()) > 0
diff --git a/tests/adapters/repository/test_indexers.py b/tests/adapters/repository/test_indexers.py
new file mode 100644
index 00000000..8b61c517
--- /dev/null
+++ b/tests/adapters/repository/test_indexers.py
@@ -0,0 +1,27 @@
+# Copyright 2021 Vincent Texier <vit@free.fr>
+#
+# This software is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This software is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from tikka.domains.application import Application
+
+
+def test_indexers_list(application: Application):
+    """
+
+
+    :param application: Application instance
+    :param account: Account instance
+    :return:
+    """
+    assert len(application.repository.indexers.list()) > 0
diff --git a/tikka/adapters/repository/accounts.py b/tikka/adapters/repository/accounts.py
index c4128d6d..872e3a3f 100644
--- a/tikka/adapters/repository/accounts.py
+++ b/tikka/adapters/repository/accounts.py
@@ -30,8 +30,6 @@ from tikka.interfaces.adapters.repository.db_repository import DBRepositoryInter
 
 TABLE_NAME = "accounts"
 
-# config sql with ? as param style
-Flavor.set(Flavor(paramstyle="qmark"))
 # create sql table wrapper
 sql_accounts_table = Table(TABLE_NAME)
 
@@ -104,7 +102,10 @@ class DBAccountsRepository(AccountsRepositoryInterface, DBRepositoryInterface):
             return And((a, b))
 
         if len(conditions) > 0:
-            sql_select.where = reduce(and_, conditions)
+            sql_select.where = reduce(and_, conditions)  # type: ignore
+
+        # config sql with ? as param style
+        Flavor.set(Flavor(paramstyle="qmark"))
 
         sql, args = tuple(sql_select)
         result_set = self.client.select(sql, args)
@@ -251,7 +252,7 @@ class DBAccountsRepository(AccountsRepositoryInterface, DBRepositoryInterface):
             return And((a, b))
 
         if len(conditions) > 0:
-            sql_select.where = reduce(and_, conditions)
+            sql_select.where = reduce(and_, conditions)  # type: ignore
 
         sql, args = tuple(sql_select)
         result_set = self.client.select(sql, args)
diff --git a/tikka/adapters/repository/indexers.py b/tikka/adapters/repository/indexers.py
index c09b403d..b3148edf 100644
--- a/tikka/adapters/repository/indexers.py
+++ b/tikka/adapters/repository/indexers.py
@@ -23,8 +23,6 @@ from tikka.interfaces.adapters.repository.indexers import IndexersRepositoryInte
 
 TABLE_NAME = "indexers"
 
-# config sql with ? as param style
-Flavor.set(Flavor(paramstyle="qmark"))
 # create sql table wrapper
 sql_indexers_table = Table(TABLE_NAME)
 
@@ -74,6 +72,9 @@ class DBIndexersRepository(IndexersRepositoryInterface, DBRepositoryInterface):
             #  create select query wrapper without order by
             sql_select = sql_indexers_table.select(offset=offset, limit=limit)
 
+        # config sql with ? as param style
+        Flavor.set(Flavor(paramstyle="qmark"))
+
         sql, args = tuple(sql_select)
         result_set = self.client.select(sql, args)
         list_ = []
diff --git a/uv.lock b/uv.lock
index 56de429d..b502bf32 100644
--- a/uv.lock
+++ b/uv.lock
@@ -1837,7 +1837,7 @@ wheels = [
 
 [[package]]
 name = "tikka"
-version = "0.14.1"
+version = "0.14.2"
 source = { editable = "." }
 dependencies = [
     { name = "dateutils" },
-- 
GitLab