From 25d1962f7bf41ed1fd052981f70fd30ee258f7ae Mon Sep 17 00:00:00 2001 From: Ivo Oskamp Date: Fri, 16 Jan 2026 13:31:20 +0100 Subject: [PATCH] Auto-commit local changes before build (2026-01-16 13:31:20) --- .last-branch | 2 +- .../src/backend/app/main/routes_run_checks.py | 30 ++++++++++++++----- docs/changelog.md | 9 ++++++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/.last-branch b/.last-branch index 071f344..502f598 100644 --- a/.last-branch +++ b/.last-branch @@ -1 +1 @@ -v20260116-06-runchecks-polling-merge-fix +v20260116-07-autotask-ticket-link-all-runs-ticketjobrun-fix diff --git a/containers/backupchecks/src/backend/app/main/routes_run_checks.py b/containers/backupchecks/src/backend/app/main/routes_run_checks.py index 0c24fdb..24fbf75 100644 --- a/containers/backupchecks/src/backend/app/main/routes_run_checks.py +++ b/containers/backupchecks/src/backend/app/main/routes_run_checks.py @@ -1145,20 +1145,38 @@ def api_run_checks_create_autotask_ticket(): # until it is explicitly resolved. now = datetime.utcnow() + # Collect the open run IDs first (stable list), then apply updates and internal linking. linked_run_ids: list[int] = [] try: - open_runs = ( + rows = ( JobRun.query.filter(JobRun.job_id == run.job_id) .filter(JobRun.reviewed_at.is_(None)) + .with_entities(JobRun.id) .order_by(JobRun.id.asc()) .all() ) + linked_run_ids = [int(rid) for (rid,) in rows if rid is not None] except Exception: - open_runs = [run] + linked_run_ids = [] # Safety: always include the explicitly selected run. - if run not in (open_runs or []): - open_runs = (open_runs or []) + [run] + try: + if run.id and int(run.id) not in linked_run_ids: + linked_run_ids.append(int(run.id)) + except Exception: + pass + + # Load run objects for the IDs we determined. + open_runs = [] + if linked_run_ids: + open_runs = JobRun.query.filter(JobRun.id.in_(linked_run_ids)).all() + else: + open_runs = [run] + try: + if run.id: + linked_run_ids = [int(run.id)] + except Exception: + linked_run_ids = [] for r in open_runs or []: # Do not overwrite an existing (different) ticket linkage. @@ -1179,9 +1197,6 @@ def api_run_checks_create_autotask_ticket(): r.autotask_ticket_created_at = now r.autotask_ticket_created_by_user_id = current_user.id - if getattr(r, "id", None): - linked_run_ids.append(int(r.id)) - # Also store an internal Ticket record and link it to the run. # This keeps Tickets/Remarks, Job Details, and Run Checks indicators consistent with the existing manual workflow. internal_ticket = None @@ -1239,6 +1254,7 @@ def api_run_checks_create_autotask_ticket(): "ticket_id": int(run.autotask_ticket_id) if run.autotask_ticket_id else None, "ticket_number": run.autotask_ticket_number or "", "already_exists": False, + "linked_run_ids": linked_run_ids or [], } ) diff --git a/docs/changelog.md b/docs/changelog.md index a1e0c70..cf5724d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -180,6 +180,15 @@ Changes: - Ensured polled PSA ticket status is available again on the Run Checks page - No changes made to ticket creation logic, resolution handling, or Backupchecks run state + +## v20260116-07-autotask-ticket-link-all-runs-ticketjobrun-fix + +### Changes: +- Fixed Autotask ticket creation linking so the internal TicketJobRun associations are created for all relevant open runs of the same job +- Ensured ticket numbers and ticket presence are consistently visible per run (Run Checks and Job Details), not only for the selected run +- Made the list of runs to link deterministic by collecting run IDs first, then applying both run field updates and internal ticket linking across that stable set +- No changes made to polling logic or PSA status interpretation + *** ## v0.1.21