From 6022cdf5fbec808f589d78cad457ca0b79d12193 Mon Sep 17 00:00:00 2001 From: louispaulb Date: Sun, 19 Jul 2026 20:36:50 -0400 Subject: [PATCH] =?UTF-8?q?fix(dispatch):=20nextJobRef=20lisait=20r.data?= =?UTF-8?q?=20(objet)=20au=20lieu=20de=20r.data.data=20=E2=86=92=20collisi?= =?UTF-8?q?ons=20ticket=5Fid=20=E2=86=92=20=C2=AB=20Failed=20to=20create?= =?UTF-8?q?=20dispatch=20job=20=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug : nextJobRef() faisait 'for..of r.data' alors que la liste ERPNext est sous r.data.data (comme partout ailleurs dans dispatch.js). r.data étant un objet → 'object is not iterable' → catch → repli ymd+'-001' à CHAQUE appel. Donc le 1er job du jour passe, les suivants COLLISIONNENT sur le même ticket_id (autoname) → POST rejeté → createDispatchJob lève 'Failed to create dispatch job'. Touchait TOUTE création via createDispatchJob (agent NL create_job, /dispatch/ create-job, chaînes d'installation), pas seulement l'assistant. Fix : itérer r.data.data. Vérifié : 2 créations consécutives → refs 20260719-001 puis -002 (distincts, incrémentés), plus d'erreur 'not iterable'. Déployé, hub sain. Co-Authored-By: Claude Fable 5 --- services/targo-hub/lib/dispatch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/targo-hub/lib/dispatch.js b/services/targo-hub/lib/dispatch.js index c070b52..ca56491 100644 --- a/services/targo-hub/lib/dispatch.js +++ b/services/targo-hub/lib/dispatch.js @@ -426,7 +426,7 @@ async function nextJobRef () { const fields = encodeURIComponent(JSON.stringify(['name'])) const r = await erpFetch(`/api/resource/Dispatch Job?filters=${filters}&fields=${fields}&limit_page_length=0`) const re = new RegExp('^' + ymd + '-(\\d{3})$') - for (const j of ((r && r.data) || [])) { const m = re.exec(String(j.name || '')); if (m) { const n = parseInt(m[1], 10); if (n > max) max = n } } + for (const j of ((r && r.data && r.data.data) || [])) { const m = re.exec(String(j.name || '')); if (m) { const n = parseInt(m[1], 10); if (n > max) max = n } } } catch (e) { log('nextJobRef: ' + e.message) } return ymd + '-' + String(max + 1).padStart(3, '0') }