diff --git a/containers/backupchecks/src/backend/app/ticketing_utils.py b/containers/backupchecks/src/backend/app/ticketing_utils.py index d8411a9..4156766 100644 --- a/containers/backupchecks/src/backend/app/ticketing_utils.py +++ b/containers/backupchecks/src/backend/app/ticketing_utils.py @@ -170,8 +170,7 @@ def link_open_internal_tickets_to_run(*, run: JobRun, job: Job) -> None: ui_tz = _get_ui_timezone_name() run_date = _to_ui_date(getattr(run, "run_at", None)) or _to_ui_date(datetime.utcnow()) - # Find open tickets scoped to this job for the run date window. - # This matches the logic used by Job Details and Run Checks indicators. + # Find open (unresolved) tickets scoped to this job. rows = [] try: rows = ( @@ -183,14 +182,11 @@ def link_open_internal_tickets_to_run(*, run: JobRun, job: Job) -> None: JOIN ticket_scopes ts ON ts.ticket_id = t.id WHERE ts.job_id = :job_id AND t.active_from_date <= :run_date - AND ( - COALESCE(ts.resolved_at, t.resolved_at) IS NULL - OR ((COALESCE(ts.resolved_at, t.resolved_at) AT TIME ZONE 'UTC' AT TIME ZONE :ui_tz)::date) >= :run_date - ) + AND COALESCE(ts.resolved_at, t.resolved_at) IS NULL ORDER BY t.start_date DESC, t.id DESC """ ), - {"job_id": int(job.id), "run_date": run_date, "ui_tz": ui_tz}, + {"job_id": int(job.id), "run_date": run_date}, ) .fetchall() ) @@ -214,6 +210,7 @@ def link_open_internal_tickets_to_run(*, run: JobRun, job: Job) -> None: pass # Strategy 1: Use internal ticket code to find matching Autotask-linked run + # The query above only returns unresolved tickets, so we can safely propagate. try: # Use the newest ticket code to find a matching prior Autotask-linked run. newest_code = (rows[0][1] or "").strip() if rows else "" diff --git a/docs/changelog-claude.md b/docs/changelog-claude.md index 338da91..cbf1430 100644 --- a/docs/changelog-claude.md +++ b/docs/changelog-claude.md @@ -6,6 +6,7 @@ This file documents all changes made to this project via Claude Code. ### Fixed - Fixed Autotask ticket not being automatically linked to new runs when internal ticket is resolved by implementing independent Autotask propagation strategy (now checks for most recent non-deleted and non-resolved Autotask ticket on job regardless of internal ticket status, ensuring PSA ticket reference persists across runs until explicitly resolved or deleted) +- Fixed internal and Autotask tickets being linked to new runs even after being resolved by removing date-based "open" logic from ticket query (tickets now only link to new runs if they are genuinely unresolved, not based on run date comparisons) ## [2026-02-09]