From c6388eebcb83dd9f8cfd638e48096e449716f4d2 Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Tue, 12 Nov 2024 09:29:00 +0100 Subject: [PATCH] database.upgrade:get_db_version - catch OperationError exceptions --- acacore/database/upgrade.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/acacore/database/upgrade.py b/acacore/database/upgrade.py index 3faba99..fce28d2 100644 --- a/acacore/database/upgrade.py +++ b/acacore/database/upgrade.py @@ -1,5 +1,6 @@ from sqlite3 import Connection from sqlite3 import DatabaseError +from sqlite3 import OperationalError from typing import Callable from packaging.version import Version @@ -14,9 +15,11 @@ # noinspection SqlResolve def get_db_version(conn: Connection) -> Version | None: - if res := conn.execute("select VALUE from Metadata where KEY like 'version'").fetchone(): - return Version(res[0]) - return None + try: + cur = conn.execute("select VALUE from Metadata where KEY like 'version'").fetchone() + return Version(cur[0]) if cur else None + except OperationalError: + raise None def set_db_version(conn: Connection, version: Version) -> Version: