v1.0.176: FOR UPDATE fix — ORDER BY LIMIT 1 вместо MAX()

This commit is contained in:
2026-06-24 18:37:48 +04:00
parent d44f8f3e6c
commit 3f58f6adcd
+3 -2
View File
@@ -17,10 +17,11 @@ def get_next_seq(contract_id):
conn.autocommit = False
with conn.cursor() as cur:
cur.execute(
"SELECT COALESCE(MAX(seq), 0) + 1 FROM spec_events WHERE contract_id = %s FOR UPDATE",
"SELECT seq FROM spec_events WHERE contract_id = %s ORDER BY seq DESC LIMIT 1 FOR UPDATE",
(contract_id,),
)
seq = cur.fetchone()[0]
row = cur.fetchone()
seq = (row[0] + 1) if row else 1
conn.commit()
return seq
except Exception: