Skip to content

Commit be3a4f7

Browse files
committed
fix: 🐛 Add an explicit rollback in case of deadlock
1 parent 4b83fb6 commit be3a4f7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

thermal_events/crud/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ def session_scope():
3434
except OperationalError as e:
3535
if "Deadlock found" in str(e):
3636
print(f"Deadlock detected. Retrying {attempt+1}/{MAX_RETRIES}...")
37+
session.rollback()
3738
time.sleep(RETRY_DELAY) # Wait before retrying
3839
else:
3940
raise # Other errors should not be retried
4041
else:
4142
raise Exception("Transaction failed after multiple retries.")
42-
except:
43+
except Exception:
4344
session.rollback()
4445
raise
4546
finally:

0 commit comments

Comments
 (0)