From 894463742f960a6e9c1042fccd473fe7940ee036 Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Mon, 24 Nov 2025 16:46:56 +0300 Subject: [PATCH] fix: Order by updated_at DESC to get latest claim record with send_to_form_approve Problem: - Multiple records exist with same claim_id in DB - One record (ID: 0eb051ec...) has send_to_form_approve.draft (updated: 2025-11-24) - Another record (ID: b532b1b3...) doesn't have send_to_form_approve (updated: 2025-11-21) - API query used LIMIT 1 without ORDER BY, could return wrong record - Form was empty because wrong record (without send_to_form_approve) was returned Solution: - Added ORDER BY updated_at DESC to get latest record first - This ensures we always get the record with send_to_form_approve.draft - Latest record has correct data structure for confirmation form Files: - backend/app/api/claims.py: Added ORDER BY updated_at DESC --- backend/app/api/claims.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/app/api/claims.py b/backend/app/api/claims.py index 7663cc3..f2cf288 100644 --- a/backend/app/api/claims.py +++ b/backend/app/api/claims.py @@ -350,6 +350,7 @@ async def get_draft(claim_id: str): # Ищем черновик по claim_id (может быть в payload->>'claim_id' или id = UUID) # Убираем фильтры по channel и status_code, чтобы находить черновики из всех каналов + # ✅ Сортируем по updated_at DESC, чтобы получить самую свежую запись (которая может иметь send_to_form_approve) query = """ SELECT id, @@ -362,6 +363,7 @@ async def get_draft(claim_id: str): updated_at FROM clpr_claims WHERE (payload->>'claim_id' = $1 OR id::text = $1) + ORDER BY updated_at DESC LIMIT 1 """