diff --git a/containers/backupchecks/src/backend/app/cove_importer.py b/containers/backupchecks/src/backend/app/cove_importer.py index 2f3b06a..08a7095 100644 --- a/containers/backupchecks/src/backend/app/cove_importer.py +++ b/containers/backupchecks/src/backend/app/cove_importer.py @@ -407,12 +407,6 @@ def _process_account(account: dict) -> bool: run_ts = int(last_run_ts_raw or 0) except (TypeError, ValueError): run_ts = 0 - external_id = f"cove-{account_id}-{run_ts}" - - existing = JobRun.query.filter_by(external_id=external_id).first() - if existing: - db.session.commit() - return False # Fetch the linked job from .models import Job @@ -421,6 +415,16 @@ def _process_account(account: dict) -> bool: db.session.commit() return False + external_id = f"cove-{account_id}-{run_ts}" + + # Deduplicate per job + session, not globally. + # This avoids blocking a run on a newly linked/relinked job when the same + # Cove session was previously stored under another job. + existing = JobRun.query.filter_by(job_id=job.id, external_id=external_id).first() + if existing: + db.session.commit() + return False + status = _map_status(last_status_code) run_remark = ( f"Cove account: {account_name or account_id} | "