fix: spec_events.py — get_pool → get_conn, remove FOR UPDATE
Deploy contracts-flask / validate (push) Successful in 0s

This commit is contained in:
2026-07-15 11:43:01 +04:00
parent aafb038921
commit f176ddad71
+6 -18
View File
@@ -1,6 +1,6 @@
"""spec_events — event sourcing: apply ops, reset contract."""
import json, uuid
from db.connection import query, execute, get_pool
from db.connection import query, execute, get_conn
def reset(contract_id):
@@ -10,26 +10,14 @@ def reset(contract_id):
def get_next_seq(contract_id):
"""Get next sequence number with row lock to prevent race conditions."""
pool = get_pool()
conn = pool.getconn()
try:
conn.autocommit = False
with conn.cursor() as cur:
cur.execute(
"SELECT seq FROM spec_events WHERE contract_id = %s ORDER BY seq DESC LIMIT 1 FOR UPDATE",
"""Get next sequence number. WAL serializes writers — no explicit lock needed."""
conn = get_conn()
cur = conn.execute(
"SELECT seq FROM spec_events WHERE contract_id = ? ORDER BY seq DESC LIMIT 1",
(contract_id,),
)
row = cur.fetchone()
seq = (row[0] + 1) if row else 1
conn.commit()
return seq
except Exception:
conn.rollback()
raise
finally:
conn.autocommit = True
pool.putconn(conn)
return (row["seq"] + 1) if row else 1
def apply_ops(contract_id, supplement_id, document_id, ops, prompt_id, raw_llm_response):