From 7dcab1d7a305b3746174b731a3c2a135d25fea8d Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 23 Mar 2026 16:35:07 +0100 Subject: [PATCH] fix: correct import skipped count when manual entries exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Import reported all entries as "updated" even when skipped due to WHERE clause (source != 'manual') Root cause: RETURNING returns NULL when WHERE clause prevents update, but code counted NULL as "updated" instead of "skipped" Fix: - Check if result is None → skipped (WHERE prevented update) - Check if xmax = 0 → inserted (new row) - Otherwise → updated (existing row modified) Affects: - vitals_baseline.py: Apple Health import - blood_pressure.py: Omron import Co-Authored-By: Claude Opus 4.6 --- backend/routers/blood_pressure.py | 5 ++++- backend/routers/vitals_baseline.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/routers/blood_pressure.py b/backend/routers/blood_pressure.py index 92bb28d..b613d3b 100644 --- a/backend/routers/blood_pressure.py +++ b/backend/routers/blood_pressure.py @@ -376,7 +376,10 @@ async def import_omron_csv( )) result = cur.fetchone() - if result and result['inserted']: + if result is None: + # WHERE clause prevented update (manual entry exists) + skipped += 1 + elif result['inserted']: inserted += 1 else: updated += 1 diff --git a/backend/routers/vitals_baseline.py b/backend/routers/vitals_baseline.py index 95b1d5d..dd8f02a 100644 --- a/backend/routers/vitals_baseline.py +++ b/backend/routers/vitals_baseline.py @@ -357,7 +357,10 @@ async def import_apple_health_baseline( )) result = cur.fetchone() - if result and result['inserted']: + if result is None: + # WHERE clause prevented update (manual entry exists) + skipped += 1 + elif result['inserted']: inserted += 1 else: updated += 1