Fix Run Checks popup showing resolved tickets
The Run Checks popup modal was still showing resolved tickets for runs where they were never actually linked. This was the last remaining location using date-based ticket logic. Root cause: The /api/job-runs/<run_id>/alerts endpoint used the old date-based logic that showed all tickets scoped to the job if active_from_date was before the run date. This ignored whether the ticket was actually linked to that specific run. Changes: - Replaced date-based query with explicit ticket_job_runs join - Replaced date-based query with explicit remark_job_runs join - Now only returns tickets/remarks actually linked to this run - Removed unused run_date, job_id, ui_tz query parameters - Simplified queries: no timezone conversions, no date comparisons Result: Resolved tickets no longer appear in popup unless they were linked to that run when they were still open. Completes transition from date-based to explicit-link ticket system across entire UI. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5b940e34f2
commit
0d9159ef6f
@ -16,7 +16,8 @@ def api_job_run_alerts(run_id: int):
|
|||||||
tickets = []
|
tickets = []
|
||||||
remarks = []
|
remarks = []
|
||||||
|
|
||||||
# Tickets active for this job on this run date (including resolved-on-day)
|
# Tickets linked to this specific run
|
||||||
|
# Only show tickets that were explicitly linked via ticket_job_runs
|
||||||
try:
|
try:
|
||||||
rows = (
|
rows = (
|
||||||
db.session.execute(
|
db.session.execute(
|
||||||
@ -30,19 +31,13 @@ def api_job_run_alerts(run_id: int):
|
|||||||
t.active_from_date
|
t.active_from_date
|
||||||
FROM tickets t
|
FROM tickets t
|
||||||
JOIN ticket_scopes ts ON ts.ticket_id = t.id
|
JOIN ticket_scopes ts ON ts.ticket_id = t.id
|
||||||
WHERE ts.job_id = :job_id
|
JOIN ticket_job_runs tjr ON tjr.ticket_id = t.id
|
||||||
AND t.active_from_date <= :run_date
|
WHERE tjr.job_run_id = :run_id
|
||||||
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
|
|
||||||
)
|
|
||||||
ORDER BY t.start_date DESC
|
ORDER BY t.start_date DESC
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
{
|
{
|
||||||
"job_id": job.id if job else None,
|
"run_id": run_id,
|
||||||
"run_date": run_date,
|
|
||||||
"ui_tz": _get_ui_timezone_name(),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.mappings()
|
.mappings()
|
||||||
@ -71,7 +66,8 @@ def api_job_run_alerts(run_id: int):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
return jsonify({"status": "error", "message": str(exc) or "Failed to load tickets."}), 500
|
return jsonify({"status": "error", "message": str(exc) or "Failed to load tickets."}), 500
|
||||||
|
|
||||||
# Remarks active for this job on this run date (including resolved-on-day)
|
# Remarks linked to this specific run
|
||||||
|
# Only show remarks that were explicitly linked via remark_job_runs
|
||||||
try:
|
try:
|
||||||
rows = (
|
rows = (
|
||||||
db.session.execute(
|
db.session.execute(
|
||||||
@ -80,22 +76,13 @@ def api_job_run_alerts(run_id: int):
|
|||||||
SELECT r.id, r.body, r.start_date, r.resolved_at, r.active_from_date
|
SELECT r.id, r.body, r.start_date, r.resolved_at, r.active_from_date
|
||||||
FROM remarks r
|
FROM remarks r
|
||||||
JOIN remark_scopes rs ON rs.remark_id = r.id
|
JOIN remark_scopes rs ON rs.remark_id = r.id
|
||||||
WHERE rs.job_id = :job_id
|
JOIN remark_job_runs rjr ON rjr.remark_id = r.id
|
||||||
AND COALESCE(
|
WHERE rjr.job_run_id = :run_id
|
||||||
r.active_from_date,
|
|
||||||
((r.start_date AT TIME ZONE 'UTC' AT TIME ZONE :ui_tz)::date)
|
|
||||||
) <= :run_date
|
|
||||||
AND (
|
|
||||||
r.resolved_at IS NULL
|
|
||||||
OR ((r.resolved_at AT TIME ZONE 'UTC' AT TIME ZONE :ui_tz)::date) >= :run_date
|
|
||||||
)
|
|
||||||
ORDER BY r.start_date DESC
|
ORDER BY r.start_date DESC
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
{
|
{
|
||||||
"job_id": job.id if job else None,
|
"run_id": run_id,
|
||||||
"run_date": run_date,
|
|
||||||
"ui_tz": _get_ui_timezone_name(),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.mappings()
|
.mappings()
|
||||||
|
|||||||
@ -9,6 +9,7 @@ This file documents all changes made to this project via Claude Code.
|
|||||||
- 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)
|
- 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)
|
||||||
- Fixed Job Details page showing resolved tickets for ALL runs by implementing two-source ticket display: directly linked tickets (via ticket_job_runs) are always shown for audit trail, while active window tickets (via scope query) are only shown if unresolved, preserving historical ticket links while preventing resolved tickets from appearing on new runs
|
- Fixed Job Details page showing resolved tickets for ALL runs by implementing two-source ticket display: directly linked tickets (via ticket_job_runs) are always shown for audit trail, while active window tickets (via scope query) are only shown if unresolved, preserving historical ticket links while preventing resolved tickets from appearing on new runs
|
||||||
- Fixed Run Checks page showing resolved ticket indicators by removing date-based logic from ticket/remark existence queries (tickets and remarks now only show indicators if genuinely unresolved)
|
- Fixed Run Checks page showing resolved ticket indicators by removing date-based logic from ticket/remark existence queries (tickets and remarks now only show indicators if genuinely unresolved)
|
||||||
|
- Fixed Run Checks popup showing resolved tickets for runs where they were never linked by replacing date-based ticket/remark queries in `/api/job-runs/<run_id>/alerts` endpoint with explicit link-based queries (now only shows tickets/remarks that were actually linked to the specific run via ticket_job_runs/remark_job_runs tables, completing the transition from date-based to explicit-link ticket system)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Added debug logging to ticket linking function to troubleshoot resolved ticket propagation issues (writes to AuditLog table with event_type "ticket_link_debug", visible on Logging page, logs EVERY run import to show whether tickets were found and their resolved_at status, uses commit instead of flush to ensure persistence)
|
- Added debug logging to ticket linking function to troubleshoot resolved ticket propagation issues (writes to AuditLog table with event_type "ticket_link_debug", visible on Logging page, logs EVERY run import to show whether tickets were found and their resolved_at status, uses commit instead of flush to ensure persistence)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user