Skip to content

Commit

Permalink
database.upgrade:get_db_version - catch OperationError exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoCampinoti94 committed Nov 12, 2024
1 parent 3e393df commit c6388ee
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions acacore/database/upgrade.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down

0 comments on commit c6388ee

Please sign in to comment.