Fix tickets not showing in Run Checks modal detail view
Extended /api/job-runs/<run_id>/alerts endpoint to include both: - Tickets explicitly linked to run via ticket_job_runs (audit trail) - Tickets linked to job via ticket_scopes (active on run date) Previously only ticket_job_runs was queried, causing newly created tickets to not appear in the Meldingen section of the Run Checks modal. They would only appear after being resolved (which creates a ticket_job_runs entry). Now both sources are queried and duplicates are prevented. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
91755c6e85
commit
c5cf07f4e5
@ -16,9 +16,11 @@ def api_job_run_alerts(run_id: int):
|
||||
tickets = []
|
||||
remarks = []
|
||||
|
||||
# Tickets linked to this specific run
|
||||
# Only show tickets that were explicitly linked via ticket_job_runs
|
||||
# Tickets linked to this run:
|
||||
# 1. Explicitly linked via ticket_job_runs (audit trail when resolved)
|
||||
# 2. Linked to the job via ticket_scopes (active on run date)
|
||||
try:
|
||||
# First, get tickets explicitly linked to this run via ticket_job_runs
|
||||
rows = (
|
||||
db.session.execute(
|
||||
text(
|
||||
@ -43,7 +45,11 @@ def api_job_run_alerts(run_id: int):
|
||||
.all()
|
||||
)
|
||||
|
||||
ticket_ids_seen = set()
|
||||
for r in rows:
|
||||
ticket_id = int(r.get("id"))
|
||||
ticket_ids_seen.add(ticket_id)
|
||||
|
||||
resolved_at = r.get("resolved_at")
|
||||
resolved_same_day = False
|
||||
if resolved_at and run_date:
|
||||
@ -52,7 +58,62 @@ def api_job_run_alerts(run_id: int):
|
||||
|
||||
tickets.append(
|
||||
{
|
||||
"id": int(r.get("id")),
|
||||
"id": ticket_id,
|
||||
"ticket_code": r.get("ticket_code") or "",
|
||||
"description": r.get("description") or "",
|
||||
"start_date": _format_datetime(r.get("start_date")),
|
||||
"active_from_date": str(r.get("active_from_date")) if r.get("active_from_date") else "",
|
||||
"resolved_at": _format_datetime(r.get("resolved_at")) if r.get("resolved_at") else "",
|
||||
"active": bool(active_now),
|
||||
"resolved_same_day": bool(resolved_same_day),
|
||||
}
|
||||
)
|
||||
|
||||
# Second, get tickets linked to the job via ticket_scopes
|
||||
# These are tickets that apply to the whole job (not just a specific run)
|
||||
rows = (
|
||||
db.session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT DISTINCT t.id,
|
||||
t.ticket_code,
|
||||
t.description,
|
||||
t.start_date,
|
||||
t.resolved_at,
|
||||
t.active_from_date
|
||||
FROM tickets t
|
||||
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
|
||||
ORDER BY t.start_date DESC
|
||||
"""
|
||||
),
|
||||
{
|
||||
"job_id": job.id if job else 0,
|
||||
"run_date": run_date,
|
||||
},
|
||||
)
|
||||
.mappings()
|
||||
.all()
|
||||
)
|
||||
|
||||
for r in rows:
|
||||
ticket_id = int(r.get("id"))
|
||||
# Skip if already added via ticket_job_runs
|
||||
if ticket_id in ticket_ids_seen:
|
||||
continue
|
||||
ticket_ids_seen.add(ticket_id)
|
||||
|
||||
resolved_at = r.get("resolved_at")
|
||||
resolved_same_day = False
|
||||
if resolved_at and run_date:
|
||||
resolved_same_day = _to_amsterdam_date(resolved_at) == run_date
|
||||
active_now = r.get("resolved_at") is None
|
||||
|
||||
tickets.append(
|
||||
{
|
||||
"id": ticket_id,
|
||||
"ticket_code": r.get("ticket_code") or "",
|
||||
"description": r.get("description") or "",
|
||||
"start_date": _format_datetime(r.get("start_date")),
|
||||
|
||||
@ -2,6 +2,11 @@
|
||||
|
||||
This file documents all changes made to this project via Claude Code.
|
||||
|
||||
## [2026-02-12]
|
||||
|
||||
### Fixed
|
||||
- Fixed tickets not being displayed in Run Checks modal detail view (Meldingen section) by extending `/api/job-runs/<run_id>/alerts` endpoint to include both run-specific tickets (via ticket_job_runs) and job-level tickets (via ticket_scopes), ensuring newly created tickets are visible immediately in the modal instead of only after being resolved
|
||||
|
||||
## [2026-02-10]
|
||||
|
||||
### Added
|
||||
|
||||
Loading…
Reference in New Issue
Block a user