Compare commits
No commits in common. "e3d109ed24f5e55c6e10f975bbc402b0d8f4266f" and "d2f761877205c69559ce7cf65d0aa440eeb0e19e" have entirely different histories.
e3d109ed24
...
d2f7618772
@ -1 +1 @@
|
||||
v20260113-07-job-delete-fix
|
||||
v20260113-06-overrides-error-match-modes
|
||||
|
||||
@ -423,17 +423,25 @@ def job_delete(job_id: int):
|
||||
job = Job.query.get_or_404(job_id)
|
||||
|
||||
try:
|
||||
# Collect run IDs up-front for cleanup across dependent tables
|
||||
run_ids = [r.id for r in JobRun.query.filter_by(job_id=job.id).all()]
|
||||
# Collect run ids for FK cleanup in auxiliary tables that may not have ON DELETE CASCADE
|
||||
run_ids = []
|
||||
mail_message_ids = []
|
||||
|
||||
# Put any related mails back into the inbox and unlink from job
|
||||
msgs = MailMessage.query.filter(MailMessage.job_id == job.id).all()
|
||||
for run in job.runs:
|
||||
if run.id is not None:
|
||||
run_ids.append(run.id)
|
||||
if run.mail_message_id:
|
||||
mail_message_ids.append(run.mail_message_id)
|
||||
|
||||
# Put related mails back into the inbox and unlink from job
|
||||
if mail_message_ids:
|
||||
msgs = MailMessage.query.filter(MailMessage.id.in_(mail_message_ids)).all()
|
||||
for msg in msgs:
|
||||
if hasattr(msg, "location"):
|
||||
msg.location = "inbox"
|
||||
msg.job_id = None
|
||||
|
||||
# Clean up tables that may not have ON DELETE CASCADE in older schemas.
|
||||
# Ensure run_object_links doesn't block job_runs deletion (older schemas may miss ON DELETE CASCADE)
|
||||
if run_ids:
|
||||
db.session.execute(
|
||||
text("DELETE FROM run_object_links WHERE run_id IN :run_ids").bindparams(
|
||||
@ -441,48 +449,14 @@ def job_delete(job_id: int):
|
||||
),
|
||||
{"run_ids": run_ids},
|
||||
)
|
||||
db.session.execute(
|
||||
text("DELETE FROM job_run_review_events WHERE run_id IN :run_ids").bindparams(
|
||||
bindparam("run_ids", expanding=True)
|
||||
),
|
||||
{"run_ids": run_ids},
|
||||
)
|
||||
db.session.execute(
|
||||
text("DELETE FROM ticket_job_runs WHERE job_run_id IN :run_ids").bindparams(
|
||||
bindparam("run_ids", expanding=True)
|
||||
),
|
||||
{"run_ids": run_ids},
|
||||
)
|
||||
db.session.execute(
|
||||
text("DELETE FROM remark_job_runs WHERE job_run_id IN :run_ids").bindparams(
|
||||
bindparam("run_ids", expanding=True)
|
||||
),
|
||||
{"run_ids": run_ids},
|
||||
)
|
||||
db.session.execute(
|
||||
text("DELETE FROM job_objects WHERE job_run_id IN :run_ids").bindparams(
|
||||
bindparam("run_ids", expanding=True)
|
||||
),
|
||||
{"run_ids": run_ids},
|
||||
)
|
||||
|
||||
# Overrides scoped to this job (object overrides)
|
||||
db.session.execute(text("UPDATE overrides SET job_id = NULL WHERE job_id = :job_id"), {"job_id": job.id})
|
||||
|
||||
# Ticket/Remark scopes may reference a specific job
|
||||
db.session.execute(text("UPDATE ticket_scopes SET job_id = NULL WHERE job_id = :job_id"), {"job_id": job.id})
|
||||
db.session.execute(text("UPDATE remark_scopes SET job_id = NULL WHERE job_id = :job_id"), {"job_id": job.id})
|
||||
|
||||
# Ensure job_object_links doesn't block jobs deletion (older schemas may miss ON DELETE CASCADE)
|
||||
if job.id is not None:
|
||||
db.session.execute(
|
||||
text("DELETE FROM job_object_links WHERE job_id = :job_id"),
|
||||
{"job_id": job.id},
|
||||
)
|
||||
|
||||
# Finally remove runs and the job itself
|
||||
if run_ids:
|
||||
db.session.execute(text("DELETE FROM job_runs WHERE job_id = :job_id"), {"job_id": job.id})
|
||||
|
||||
db.session.delete(job)
|
||||
db.session.commit()
|
||||
flash("Job deleted. Related mails are returned to the inbox.", "success")
|
||||
|
||||
@ -43,14 +43,6 @@
|
||||
- Extended overrides UI with a match type selector and improved edit support for existing overrides
|
||||
- Added database migration to create and backfill overrides.match_error_mode for existing records
|
||||
|
||||
---
|
||||
|
||||
## v20260113-07-job-delete-fix
|
||||
|
||||
- Fixed an error that occurred when deleting a job.
|
||||
- Corrected backend deletion logic to prevent exceptions during job removal.
|
||||
- Ensured related records are handled safely to avoid constraint or reference errors.
|
||||
|
||||
***
|
||||
|
||||
## v0.1.20
|
||||
|
||||
Loading…
Reference in New Issue
Block a user