fix(exam): dedupe all AI auto-map rows by id before insert
api-ci-deploy / test-build-deploy (push) Has been cancelled
api-ci-deploy / test-build-deploy (push) Has been cancelled
B1-4 live-route validation: continuation bands re-emit the same stable AI id for response_areas/boundaries/layout (not just questions), causing duplicate-pkey insert failures. Add _dedupe_rows_by_id applied to all four tables in _refresh_ai_rows. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
150b915282
commit
e83873e822
@@ -642,6 +642,20 @@ def test_auto_map_fast_path_merges_ai_rows_and_returns_detail(monkeypatch):
|
||||
assert store["exam_boundaries"] and store["exam_boundaries"][0]["derivation"] == "docling-main-band"
|
||||
|
||||
|
||||
def test_auto_map_deduplicates_repeated_response_area_ids(monkeypatch):
|
||||
store = _template_with_source()
|
||||
client, store = make_client(store=store)
|
||||
_patch_auto_map(monkeypatch, store, fast=True)
|
||||
dup = {"page_index": 0, "bbox": {"l": 50, "t": 700, "r": 100, "b": 680, "coord_origin": "BOTTOMLEFT"}, "region_type": "answer_lines", "confidence": 0.9}
|
||||
monkeypatch.setattr(templates_mod, "detect_response_regions_from_pdf", lambda *_a, **_k: [dup, dict(dup)])
|
||||
|
||||
resp = client.post("/api/exam/templates/t1/auto-map")
|
||||
|
||||
assert resp.status_code == 200
|
||||
response_area_ids = [r["id"] for r in store["exam_response_areas"]]
|
||||
assert len(response_area_ids) == len(set(response_area_ids))
|
||||
|
||||
|
||||
def test_auto_map_preserves_manual_and_confirmed_rows_on_rerun(monkeypatch):
|
||||
store = _template_with_source()
|
||||
store.update({
|
||||
|
||||
Reference in New Issue
Block a user