fix: UNRESOLVED для пустых target_hash/name + неизвестный action
This commit is contained in:
@@ -45,6 +45,11 @@ def apply_ops(contract_id, supplement_id, document_id, ops, prompt_id, raw_llm_r
|
|||||||
if action == "ADD":
|
if action == "ADD":
|
||||||
nr = op.get("new_row", {})
|
nr = op.get("new_row", {})
|
||||||
name = nr.get("name", "")
|
name = nr.get("name", "")
|
||||||
|
if not name:
|
||||||
|
# ADD without name → UNRESOLVED
|
||||||
|
_log_unresolved(contract_id, supplement_id, seq, op, prompt_id, document_id, raw_llm_response, "ADD with empty name")
|
||||||
|
seq += 1
|
||||||
|
continue
|
||||||
name_hash = _hash(name, nr.get("date_start"))
|
name_hash = _hash(name, nr.get("date_start"))
|
||||||
execute(
|
execute(
|
||||||
"""INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash,
|
"""INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash,
|
||||||
@@ -64,6 +69,10 @@ def apply_ops(contract_id, supplement_id, document_id, ops, prompt_id, raw_llm_r
|
|||||||
elif action == "UPDATE":
|
elif action == "UPDATE":
|
||||||
nv = op.get("new_values", {})
|
nv = op.get("new_values", {})
|
||||||
th = op.get("target_hash", "")
|
th = op.get("target_hash", "")
|
||||||
|
if not th:
|
||||||
|
_log_unresolved(contract_id, supplement_id, seq, op, prompt_id, document_id, raw_llm_response, "UPDATE with empty target_hash")
|
||||||
|
seq += 1
|
||||||
|
continue
|
||||||
execute(
|
execute(
|
||||||
"""INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash,
|
"""INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash,
|
||||||
new_values, comment, status, prompt_version, source_document_id, raw_llm_response)
|
new_values, comment, status, prompt_version, source_document_id, raw_llm_response)
|
||||||
@@ -81,6 +90,10 @@ def apply_ops(contract_id, supplement_id, document_id, ops, prompt_id, raw_llm_r
|
|||||||
|
|
||||||
elif action == "DELETE":
|
elif action == "DELETE":
|
||||||
th = op.get("target_hash", "")
|
th = op.get("target_hash", "")
|
||||||
|
if not th:
|
||||||
|
_log_unresolved(contract_id, supplement_id, seq, op, prompt_id, document_id, raw_llm_response, "DELETE with empty target_hash")
|
||||||
|
seq += 1
|
||||||
|
continue
|
||||||
execute(
|
execute(
|
||||||
"""INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash,
|
"""INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash,
|
||||||
new_values, comment, status, prompt_version, source_document_id, raw_llm_response)
|
new_values, comment, status, prompt_version, source_document_id, raw_llm_response)
|
||||||
@@ -113,9 +126,31 @@ def apply_ops(contract_id, supplement_id, document_id, ops, prompt_id, raw_llm_r
|
|||||||
)
|
)
|
||||||
seq += 1
|
seq += 1
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Unknown action — log as UNRESOLVED
|
||||||
|
_log_unresolved(contract_id, supplement_id, seq, op, prompt_id, document_id, raw_llm_response,
|
||||||
|
f"unknown action: {action}")
|
||||||
|
|
||||||
return {"added": added, "updated": updated, "deleted": deleted}
|
return {"added": added, "updated": updated, "deleted": deleted}
|
||||||
|
|
||||||
|
|
||||||
|
def _log_unresolved(contract_id, supplement_id, seq, op, prompt_id, document_id, raw_llm_response, reason):
|
||||||
|
"""Log an op as UNRESOLVED instead of silently ignoring it."""
|
||||||
|
execute(
|
||||||
|
"""INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash,
|
||||||
|
new_values, comment, status, prompt_version, source_document_id, raw_llm_response)
|
||||||
|
VALUES (%s, %s, %s, 'UNRESOLVED', %s, %s, %s, 'unresolved', %s, %s, %s)""",
|
||||||
|
(
|
||||||
|
contract_id, supplement_id, seq,
|
||||||
|
op.get("target_hash", ""),
|
||||||
|
json.dumps(op.get("new_values", op.get("new_row", {})) or {}, ensure_ascii=False),
|
||||||
|
reason,
|
||||||
|
prompt_id, document_id,
|
||||||
|
json.dumps(raw_llm_response, ensure_ascii=False),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _hash(name, date_start=None):
|
def _hash(name, date_start=None):
|
||||||
"""Нормализованный хеш услуги. Включает date_start чтобы различать периоды."""
|
"""Нормализованный хеш услуги. Включает date_start чтобы различать периоды."""
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|||||||
Reference in New Issue
Block a user