fix: spec_events.py — get_pool → get_conn, remove FOR UPDATE
Deploy contracts-flask / validate (push) Successful in 0s
Deploy contracts-flask / validate (push) Successful in 0s
This commit is contained in:
+6
-18
@@ -1,6 +1,6 @@
|
|||||||
"""spec_events — event sourcing: apply ops, reset contract."""
|
"""spec_events — event sourcing: apply ops, reset contract."""
|
||||||
import json, uuid
|
import json, uuid
|
||||||
from db.connection import query, execute, get_pool
|
from db.connection import query, execute, get_conn
|
||||||
|
|
||||||
|
|
||||||
def reset(contract_id):
|
def reset(contract_id):
|
||||||
@@ -10,26 +10,14 @@ def reset(contract_id):
|
|||||||
|
|
||||||
|
|
||||||
def get_next_seq(contract_id):
|
def get_next_seq(contract_id):
|
||||||
"""Get next sequence number with row lock to prevent race conditions."""
|
"""Get next sequence number. WAL serializes writers — no explicit lock needed."""
|
||||||
pool = get_pool()
|
conn = get_conn()
|
||||||
conn = pool.getconn()
|
cur = conn.execute(
|
||||||
try:
|
"SELECT seq FROM spec_events WHERE contract_id = ? ORDER BY seq DESC LIMIT 1",
|
||||||
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",
|
|
||||||
(contract_id,),
|
(contract_id,),
|
||||||
)
|
)
|
||||||
row = cur.fetchone()
|
row = cur.fetchone()
|
||||||
seq = (row[0] + 1) if row else 1
|
return (row["seq"] + 1) if row else 1
|
||||||
conn.commit()
|
|
||||||
return seq
|
|
||||||
except Exception:
|
|
||||||
conn.rollback()
|
|
||||||
raise
|
|
||||||
finally:
|
|
||||||
conn.autocommit = True
|
|
||||||
pool.putconn(conn)
|
|
||||||
|
|
||||||
|
|
||||||
def apply_ops(contract_id, supplement_id, document_id, ops, prompt_id, raw_llm_response):
|
def apply_ops(contract_id, supplement_id, document_id, ops, prompt_id, raw_llm_response):
|
||||||
|
|||||||
Reference in New Issue
Block a user