Compare commits

..

No commits in common. "44233203e498a269ec6a9f4db497c65dfe988b11" and "01816813ee31b1a7077b9bca1c19458da05acf3a" have entirely different histories.

3 changed files with 34 additions and 73 deletions

View File

@ -1 +1 @@
v20260106-22-ticket-link-multiple-jobs backupchecks-v20260106-21-changelog-0.1.17

View File

@ -204,44 +204,10 @@ def api_tickets():
if not re.match(r"^T\d{8}\.\d{4}$", ticket_code): if not re.match(r"^T\d{8}\.\d{4}$", ticket_code):
return jsonify({"status": "error", "message": "Invalid ticket_code format. Expected TYYYYMMDD.####."}), 400 return jsonify({"status": "error", "message": "Invalid ticket_code format. Expected TYYYYMMDD.####."}), 400
existing = Ticket.query.filter_by(ticket_code=ticket_code).first() # Ensure uniqueness
if Ticket.query.filter_by(ticket_code=ticket_code).first():
return jsonify({"status": "error", "message": "ticket_code already exists."}), 409
# If the ticket already exists, link it to this job/run (a single ticket number can apply to multiple jobs).
if existing:
ticket = existing
try:
# Ensure there is at least one job scope for this ticket/job combination.
if job and job.id:
scope = TicketScope.query.filter_by(
ticket_id=ticket.id,
scope_type="job",
job_id=job.id,
).first()
if not scope:
scope = TicketScope(
ticket_id=ticket.id,
scope_type="job",
customer_id=job.customer_id,
backup_software=job.backup_software,
backup_type=job.backup_type,
job_id=job.id,
job_name_match=job.job_name,
job_name_match_mode="exact",
)
db.session.add(scope)
# Link the ticket to this specific run (idempotent due to unique constraint).
existing_link = TicketJobRun.query.filter_by(ticket_id=ticket.id, job_run_id=run.id).first()
if not existing_link:
link = TicketJobRun(ticket_id=ticket.id, job_run_id=run.id, link_source="manual")
db.session.add(link)
db.session.commit()
except Exception as exc:
db.session.rollback()
return jsonify({"status": "error", "message": str(exc) or "Failed to link ticket."}), 500
else:
ticket = Ticket( ticket = Ticket(
ticket_code=ticket_code, ticket_code=ticket_code,
title=None, title=None,
@ -285,8 +251,8 @@ def api_tickets():
"description": ticket.description or "", "description": ticket.description or "",
"start_date": _format_datetime(ticket.start_date), "start_date": _format_datetime(ticket.start_date),
"active_from_date": str(ticket.active_from_date) if getattr(ticket, "active_from_date", None) else "", "active_from_date": str(ticket.active_from_date) if getattr(ticket, "active_from_date", None) else "",
"resolved_at": _format_datetime(ticket.resolved_at) if getattr(ticket, "resolved_at", None) else "", "resolved_at": "",
"active": getattr(ticket, "resolved_at", None) is None, "active": True,
}, },
} }
) )

View File

@ -1,8 +1,3 @@
## v20260106-22-ticket-link-multiple-jobs
- Fixed ticket linking logic to allow the same existing ticket number to be associated with multiple jobs and job runs.
- Prevented duplicate ticket creation errors when reusing an existing ticket_code.
- Ensured tickets are reused and linked instead of rejected when already present in the system.
================================================================================================================================================ ================================================================================================================================================