sinks/wealthfolio: treat duplicates as success in import-summary check

The IMAP cronjob re-processes the full mailbox window on every run, so
on steady-state runs all activities come back tagged duplicate=N. The
existing logic raises ImportValidationError whenever imported_n < total_n,
which makes the cron exit 1 (and the Job is reported FAILED) even though
the data path is healthy.

Treat (imported + duplicates) as "accounted for". Only raise when rows
go missing entirely (silently dropped / validation rejected).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Viktor Barzin 2026-05-26 22:52:11 +00:00
parent 2fb1fbbdd8
commit 0ab069349f

View file

@ -247,10 +247,14 @@ class WealthfolioSink:
if summary is not None:
imported_n = int(summary.get("imported", 0))
total_n = int(summary.get("total", len(valid_rows)))
if imported_n < total_n:
dupes = int(summary.get("duplicates", 0))
skipped = int(summary.get("skipped", 0))
# Duplicates are expected on every re-run (the cron re-processes the
# full IMAP window each night) — treat (imported + duplicates) as
# accounted-for. Only fail if something was genuinely lost.
accounted = imported_n + dupes
if accounted < total_n:
err_msg = summary.get("errorMessage") or "no errorMessage"
skipped = int(summary.get("skipped", 0))
dupes = int(summary.get("duplicates", 0))
raise ImportValidationError(f"Wealthfolio /import persisted {imported_n}/{total_n} "
f"(skipped={skipped} duplicates={dupes}). "
f"errorMessage: {err_msg}")