From 31005d240a3c38305195f04a0595447b20c0d1e0 Mon Sep 17 00:00:00 2001
From: Andreas <andreasv@fsmpi.rwth-aachen.de>
Date: Tue, 16 Jan 2018 12:13:44 +0100
Subject: [PATCH] fixed restarting transactions... again

---
 db.py | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/db.py b/db.py
index 105c8dc..356da83 100644
--- a/db.py
+++ b/db.py
@@ -67,15 +67,7 @@ elif config['DB_ENGINE'] == 'mysql':
 		else:
 			db = mysql.connector.connect(user=config['MYSQL_USER'], password=config['MYSQL_PASSWD'], unix_socket=config.get('MYSQL_UNIX', None))
 		cur = db.cursor()
-		tries = 0
-		while (tries < 10):
-			try:
-				cur.execute(operation)
-			except mysql.connector.errors.InternalError as e:
-				if e.msg == 'Deadlock found when trying to get lock; try restarting transaction':
-					tries += 1
-				else:
-					raise
+		cur.execute(operation)
 		rows = []
 		try:
 			rows = cur.fetchall()
@@ -95,7 +87,17 @@ elif config['DB_ENGINE'] == 'mysql':
 def query(operation, *params, delim="sep", nlfix=True):
 	operation, params = fix_query(operation, params)
 	cur = get_dbcursor()
-	cur.execute(operation, params)
+	tries = 0
+	while (tries < 10):
+		try:
+			cur.execute(operation, params)
+		except mysql.connector.errors.InternalError as e:
+			if e.msg == 'Deadlock found when trying to get lock; try restarting transaction':
+				tries += 1
+				continue
+			else:
+				raise
+		break
 	rows = []
 	try:
 		rows = cur.fetchall()
-- 
GitLab