Auto-commit local changes before build (2026-01-19 15:59:26)
This commit is contained in:
parent
4b3b6162a0
commit
b56cdacf6b
@ -1 +1 @@
|
||||
v20260119-16-fix-runchecks-render-modal
|
||||
v20260119-17-fix-autotask-postcreate-ticketnumber-internal-linking
|
||||
|
||||
@ -1331,15 +1331,50 @@ def api_run_checks_create_autotask_ticket():
|
||||
if not ticket_id:
|
||||
return jsonify({"status": "error", "message": "Autotask did not return a ticket id."}), 400
|
||||
|
||||
# Mandatory post-create retrieval: create response does not reliably include Ticket Number.
|
||||
ticket_number_str = (str(ticket_number).strip() if ticket_number is not None else "").strip()
|
||||
try:
|
||||
if not ticket_number_str:
|
||||
fetched = client.get_ticket(int(ticket_id))
|
||||
if isinstance(fetched, dict):
|
||||
ticket_number_str = (
|
||||
str(fetched.get("ticketNumber") or fetched.get("number") or fetched.get("ticket_number") or "").strip()
|
||||
)
|
||||
except Exception:
|
||||
ticket_number_str = ticket_number_str
|
||||
|
||||
now = datetime.utcnow()
|
||||
|
||||
try:
|
||||
run.autotask_ticket_id = int(ticket_id)
|
||||
except Exception:
|
||||
run.autotask_ticket_id = None
|
||||
|
||||
run.autotask_ticket_number = (str(ticket_number).strip() if ticket_number is not None else "") or None
|
||||
run.autotask_ticket_created_at = datetime.utcnow()
|
||||
run.autotask_ticket_number = (ticket_number_str or "") or None
|
||||
run.autotask_ticket_created_at = now
|
||||
run.autotask_ticket_created_by_user_id = current_user.id
|
||||
|
||||
# Propagate linkage to all active (unreviewed) runs of the same job.
|
||||
active_runs: list[JobRun] = []
|
||||
try:
|
||||
active_runs = JobRun.query.filter(JobRun.job_id == job.id, JobRun.reviewed_at.is_(None)).all()
|
||||
except Exception:
|
||||
active_runs = [run]
|
||||
|
||||
run_ids: list[int] = []
|
||||
for rr in active_runs or []:
|
||||
if getattr(rr, "id", None):
|
||||
run_ids.append(int(rr.id))
|
||||
if getattr(rr, "autotask_ticket_id", None) is None:
|
||||
rr.autotask_ticket_id = int(ticket_id)
|
||||
if ticket_number_str and not (getattr(rr, "autotask_ticket_number", None) or "").strip():
|
||||
rr.autotask_ticket_number = ticket_number_str
|
||||
db.session.add(rr)
|
||||
|
||||
# Create/repair internal Ticket + TicketJobRun links (legacy UI compatibility).
|
||||
if ticket_number_str:
|
||||
_ensure_internal_ticket_for_autotask(ticket_number=ticket_number_str, job=job, run_ids=run_ids, now=now)
|
||||
|
||||
try:
|
||||
db.session.add(run)
|
||||
db.session.commit()
|
||||
@ -1347,6 +1382,18 @@ def api_run_checks_create_autotask_ticket():
|
||||
db.session.rollback()
|
||||
return jsonify({"status": "error", "message": f"Failed to store ticket reference: {exc}"}), 500
|
||||
|
||||
# If Ticket Number is still unknown, surface that explicitly (ticket id is still stored).
|
||||
if not (run.autotask_ticket_number or "").strip():
|
||||
return jsonify(
|
||||
{
|
||||
"status": "ok",
|
||||
"ticket_id": int(run.autotask_ticket_id) if run.autotask_ticket_id else None,
|
||||
"ticket_number": "",
|
||||
"already_exists": False,
|
||||
"warning": "Ticket created, but ticket number could not be retrieved.",
|
||||
}
|
||||
)
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"status": "ok",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user