From 04cb3f5bfe707974b42b4b6785c23c261d989f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Thu, 16 Jul 2026 08:09:29 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20process.py=20=E2=80=94=20use=20apply=5Fo?= =?UTF-8?q?ps()=20instead=20of=20phantom=20add=5Frow/update=5Frow/delete?= =?UTF-8?q?=5Frow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/services/process.py | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/site/services/process.py b/site/services/process.py index 39b6fe8..c56d827 100644 --- a/site/services/process.py +++ b/site/services/process.py @@ -86,27 +86,21 @@ def run_pipeline(contract_id, order_ids, build_prompt_fn): "time_s": round(time.time() - t1, 1), } - # Apply ops to DB - applied_ops = [] - summary = {"added": 0, "updated": 0, "deleted": 0, "unresolved": 0} - for op in ops: - action = op.get("action", "UNRESOLVED") - summary[action.lower()] = summary.get(action.lower(), 0) + 1 - try: - if action == "ADD": - nr = op.get("new_row", {}) - spec_events.add_row(contract_id, sid, nr) - elif action == "UPDATE": - nr = op.get("new_row", {}) - nv = op.get("new_values", {}) - target = op.get("target_hash", "") - spec_events.update_row(contract_id, sid, target, nr, nv) - elif action == "DELETE": - target = op.get("target_hash", "") - spec_events.delete_row(contract_id, sid, target) - applied_ops.append(op) - except Exception: - summary["unresolved"] = summary.get("unresolved", 0) + 1 + # Apply ops to DB via apply_ops + try: + summary = spec_events.apply_ops( + contract_id, sid, s["document_id"], ops, prompt_id, result + ) + applied_ops = ops + except Exception as e: + summary = {"added": 0, "updated": 0, "deleted": 0, "unresolved": len(ops)} + applied_ops = [] + yield { + "type": "extract_error", + "supplement_id": sid, + "filename": filename, + "error": str(e), + } # Arithmetic check check_arithmetic(contract_id)