From 585440ebfdcf5b50b1666f6cc53febeaff44aa40 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 18:34:33 +0000 Subject: [PATCH 1/4] Initial plan From 129dec4b15d10030699ab5bbba88d4adc50d8660 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 18:37:21 +0000 Subject: [PATCH 2/4] fix: address review comments on db.py thread safety and resource leaks Co-authored-by: PhBouzid <15084032+PhBouzid@users.noreply.github.com> --- src/db.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/db.py b/src/db.py index 175f546..9bd16db 100644 --- a/src/db.py +++ b/src/db.py @@ -30,8 +30,6 @@ class DbException(Exception): class DB: - _lock = threading.Lock() - def __init__(self, dbfile): """ Create a connection to sqlite database @@ -42,6 +40,7 @@ def __init__(self, dbfile): :__tableName: table name for jobs """ self.__dbfile = dbfile + self._lock = threading.Lock() try: log.debug("Database file: %s" % self.__dbfile) self.__conn = DB.__create_connection(dbfile) @@ -77,37 +76,44 @@ def __create_table(self, query): log.exception("Database Error: %s" % err) return 0 - @staticmethod - def __log_and_execute(cursor, sql, args): - with DB._lock: + def __log_and_execute(self, cursor, sql, args): + with self._lock: log.debug("SQL command: " + sql.replace('?', '%s') % args) cursor.execute(sql, args) def __insert_or_delete(self, query, params, login=False): try: if login: - cursor = DB.__create_connection(self.__dbfile).cursor() + conn = DB.__create_connection(self.__dbfile) + cursor = conn.cursor() else: cursor = self.__conn.cursor() with cursor: - DB.__log_and_execute(cursor, query, params) + self.__log_and_execute(cursor, query, params) return 1 except apsw.Error as err: log.exception("Database Error: %s" % err) return 0 + finally: + if login and 'conn' in locals(): + conn.close() def __select(self, query, params, login=False): try: if login: - cursor = DB.__create_connection(self.__dbfile).cursor() + conn = DB.__create_connection(self.__dbfile) + cursor = conn.cursor() else: cursor = self.__conn.cursor() with cursor: - DB.__log_and_execute(cursor, query, params) + self.__log_and_execute(cursor, query, params) return cursor.fetchall() except apsw.Error as err: log.exception("Database Error: %s" % err) return None + finally: + if login and 'conn' in locals(): + conn.close() def update_job(self, task_id, type, status, vault, error, login=False): # this is required as java json convertion fails for None value of error From 2cab9ba9507d353d5ea27ec362c42a8a52825163 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 18:40:35 +0000 Subject: [PATCH 3/4] fix: remove APSW cursor context managers (not supported) Co-authored-by: PhBouzid <15084032+PhBouzid@users.noreply.github.com> --- src/db.py | 17 ++++++++--------- test.db | 0 2 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 test.db diff --git a/src/db.py b/src/db.py index 9bd16db..38984dd 100644 --- a/src/db.py +++ b/src/db.py @@ -70,8 +70,7 @@ def __create_connection(db_file): def __create_table(self, query): try: cursor = self.__conn.cursor() - with cursor: - cursor.execute(query) + cursor.execute(query) except apsw.Error as err: log.exception("Database Error: %s" % err) return 0 @@ -82,37 +81,37 @@ def __log_and_execute(self, cursor, sql, args): cursor.execute(sql, args) def __insert_or_delete(self, query, params, login=False): + conn = None try: if login: conn = DB.__create_connection(self.__dbfile) cursor = conn.cursor() else: cursor = self.__conn.cursor() - with cursor: - self.__log_and_execute(cursor, query, params) + self.__log_and_execute(cursor, query, params) return 1 except apsw.Error as err: log.exception("Database Error: %s" % err) return 0 finally: - if login and 'conn' in locals(): + if conn is not None: conn.close() def __select(self, query, params, login=False): + conn = None try: if login: conn = DB.__create_connection(self.__dbfile) cursor = conn.cursor() else: cursor = self.__conn.cursor() - with cursor: - self.__log_and_execute(cursor, query, params) - return cursor.fetchall() + self.__log_and_execute(cursor, query, params) + return cursor.fetchall() except apsw.Error as err: log.exception("Database Error: %s" % err) return None finally: - if login and 'conn' in locals(): + if conn is not None: conn.close() def update_job(self, task_id, type, status, vault, error, login=False): diff --git a/test.db b/test.db new file mode 100644 index 0000000..e69de29 From d5fd1150979e6ea353e4c6cec65c3015c46b9358 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 18:40:57 +0000 Subject: [PATCH 4/4] chore: remove accidentally committed test.db and update gitignore Co-authored-by: PhBouzid <15084032+PhBouzid@users.noreply.github.com> --- .gitignore | 2 +- test.db | 0 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 test.db diff --git a/.gitignore b/.gitignore index ecca9c4..aa706a2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ /.venv _build/ *.iml -# \ No newline at end of file +#*.db diff --git a/test.db b/test.db deleted file mode 100644 index e69de29..0000000