From c623c65fda619ac3fc0c4e34d13e969a64a7bb36 Mon Sep 17 00:00:00 2001 From: forest Date: Tue, 23 Mar 2021 15:58:40 -0500 Subject: [PATCH] Limit the utilization of serializable transactions A user encountered this error when deleting a vm: self.cursor.execute("UPDATE vms SET deleted = now() WHERE email = %s AND id = %s", ( email, id)) psycopg2.errors.SerializationFailure: could not serialize access due to read/write dependencies among transactions --- capsulflask/db_model.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/capsulflask/db_model.py b/capsulflask/db_model.py index 46101da..be44d30 100644 --- a/capsulflask/db_model.py +++ b/capsulflask/db_model.py @@ -13,7 +13,7 @@ class DBModel: def __init__(self, connection, cursor): self.connection = connection self.cursor = cursor - self.cursor.execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;") + # ------ LOGIN --------- @@ -361,6 +361,7 @@ class DBModel: def claim_operation(self, operation_id: int, host_id: str) -> bool: # have to make a new cursor to set isolation level # cursor = self.connection.cursor() + self.cursor.execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;") self.cursor.execute(""" BEGIN TRANSACTION; UPDATE host_operation SET assignment_status = 'assigned'