Updating a tasks due_date with the shotgun python api deletes the task (FIXED)

Hello Forum! I’m currently having issues with my ShotgunEventDaemon. Hoping I can get some help here :slight_smile:

The purpose of my script is to:
If a user updates there task status to “In Progress”, then set the start_date of that task to the current date.
If a user updates there task status to “Final”, then set the due_date of that task to the current date.

I’ve setup the script and everything seems to work fine until I change a task status to “Final”, for some reason whenever I do this, the entire task is deleted.

Here’s my code:

import os
import logging
import pprint
import datetime
from datetime import date

def registerCallbacks(reg):
    eventFilter = {'Shotgun_Task_Change': ['sg_status_list']}

    reg.registerCallback(
        'name',
        'key',
        taskStatusGanttChart,
        eventFilter,
        None
        )

    reg.logger.setLevel(logging.DEBUG)


#This function will only run if Shotgun Daemon System catches a Task Status Change
def taskStatusGanttChart(sg,logger,event,args):
    task_due_date = sg.find_one("Task", [["id", "is", event['meta']['entity_id']]], ['due_date'])
    due_date = task_due_date['due_date']                                                            #Get Tasks Due_Date
    
    task_start_date = sg.find_one("Task", [["id", "is", event['meta']['entity_id']]], ['start_date'])
    start_date = task_start_date['start_date']                                                      #Get Tasks Start_Date
    
    today = date.today()
    tomorrow = today + datetime.timedelta(days=1)                                                   #Get today and tomorrows current date
    
    #If the task was "Waiting to Start" and has been changed to "In Progress" then update the start_date to today
    if event['meta']['new_value'] == 'ip' and event['meta']['old_value'] == 'wtg':
        if(str(today) != str(start_date)):
            sg.update('Task', event['meta']['entity_id'], {'start_date': today})
    
    #If the task is updated to "Final" then update the due_date to the current date
    if event['meta']['new_value'] == 'fin':
        if(str(due_date) != str(today)):
            sg.update('Task', event['meta']['entity_id'], {'due_date': today})
2 Likes

Ok so it turned out, someone had turned the filter to ONLY display tasks that were “Waiting to Start” and “In Progress”. They were never deleted just not displaying, silly me :smiley:

1 Like