Skip to content

Commit

Permalink
fix: remove ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
JensZack committed Nov 21, 2024
1 parent 595823d commit ae6efdf
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/plexosdb/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ def add_object(
-----
By default, we add all objects to the system membership.
Raises
------
sqlite.IntegrityError
if an object is inserted without a unique name/class pair
Returns
-------
int
Expand All @@ -461,17 +466,14 @@ def add_object(

params = (object_name, class_id, category_id, str(uuid.uuid4()), description)
placeholders = ", ".join("?" * len(params))
try:
with self._conn as conn:
cursor = conn.cursor()
cursor.execute(
f"INSERT INTO {Schema.Objects.name}(name, class_id, category_id, GUID, description) "
f"VALUES({placeholders})",
params,
)
object_id = cursor.lastrowid
except sqlite3.IntegrityError as err:
raise ValueError(err)
with self._conn as conn:
cursor = conn.cursor()
cursor.execute(
f"INSERT INTO {Schema.Objects.name}(name, class_id, category_id, GUID, description) "
f"VALUES({placeholders})",
params,
)
object_id = cursor.lastrowid

if object_id is None:
raise TypeError("Could not fetch the last row of the insert. Check query format.")
Expand Down

0 comments on commit ae6efdf

Please sign in to comment.