Fix Autotask propagation to also check resolved status
The previous fix only checked if tickets were deleted, but Autotask tickets can also be resolved (which is tracked via the internal Ticket table, not the JobRun table). Updated Strategy 2 to: 1. Find most recent non-deleted Autotask ticket 2. Check if its internal ticket is resolved 3. Only propagate if ticket is not deleted AND not resolved This ensures tickets stop propagating when they are resolved in Autotask (synced via PSA polling), matching the expected behavior. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f3b1b56b6a
commit
caff435f96
@ -235,7 +235,7 @@ def link_open_internal_tickets_to_run(*, run: JobRun, job: Job) -> None:
|
||||
pass
|
||||
|
||||
# Strategy 2: Direct Autotask propagation (independent of internal ticket status)
|
||||
# Find the most recent non-deleted Autotask ticket for this job and propagate it.
|
||||
# Find the most recent non-deleted, non-resolved Autotask ticket for this job.
|
||||
try:
|
||||
prior = (
|
||||
JobRun.query.filter(JobRun.job_id == job.id)
|
||||
@ -245,6 +245,15 @@ def link_open_internal_tickets_to_run(*, run: JobRun, job: Job) -> None:
|
||||
.first()
|
||||
)
|
||||
if prior and getattr(prior, "autotask_ticket_id", None):
|
||||
# Check if the internal ticket is resolved (Autotask tickets are resolved via internal Ticket)
|
||||
ticket_number = (getattr(prior, "autotask_ticket_number", None) or "").strip()
|
||||
if ticket_number:
|
||||
internal_ticket = Ticket.query.filter_by(ticket_code=ticket_number).first()
|
||||
if internal_ticket and getattr(internal_ticket, "resolved_at", None):
|
||||
# Ticket is resolved, don't propagate
|
||||
return
|
||||
|
||||
# Ticket is not deleted and not resolved, propagate it
|
||||
run.autotask_ticket_id = prior.autotask_ticket_id
|
||||
run.autotask_ticket_number = prior.autotask_ticket_number
|
||||
run.autotask_ticket_created_at = getattr(prior, "autotask_ticket_created_at", None)
|
||||
|
||||
@ -5,7 +5,7 @@ This file documents all changes made to this project via Claude Code.
|
||||
## [2026-02-10]
|
||||
|
||||
### Fixed
|
||||
- Fixed Autotask ticket not being automatically linked to new runs when internal ticket is resolved by implementing independent Autotask propagation strategy (now checks for most recent non-deleted Autotask ticket on job regardless of internal ticket status, ensuring PSA ticket reference persists across runs)
|
||||
- Fixed Autotask ticket not being automatically linked to new runs when internal ticket is resolved by implementing independent Autotask propagation strategy (now checks for most recent non-deleted and non-resolved Autotask ticket on job regardless of internal ticket status, ensuring PSA ticket reference persists across runs until explicitly resolved or deleted)
|
||||
|
||||
## [2026-02-09]
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user