diff --git a/pype/ftrack/events/event_next_task_update.py b/pype/ftrack/events/event_next_task_update.py index cd26325414..9e4148e30a 100644 --- a/pype/ftrack/events/event_next_task_update.py +++ b/pype/ftrack/events/event_next_task_update.py @@ -42,41 +42,47 @@ class NextTaskUpdate(BaseEvent): for entity in event['data'].get('entities', []): - if (entity['entityType'] == 'task' and - 'statusid' in entity['keys']): + statusid_changes = entity.get('changes', {}).get('statusid', {}) + if ( + entity['entityType'] != 'task' or + 'statusid' not in entity['keys'] or + statusid_changes.get('new', None) is None or + statusid_changes.get('old', None) is None + ): + continue - task = session.get('Task', entity['entityId']) + task = session.get('Task', entity['entityId']) - status = session.get('Status', - entity['changes']['statusid']['new']) - state = status['state']['name'] + status = session.get('Status', + entity['changes']['statusid']['new']) + state = status['state']['name'] - next_task = self.get_next_task(task, session) + next_task = self.get_next_task(task, session) - # Setting next task to Ready, if on NOT READY - if next_task and state == 'Done': - if next_task['status']['name'].lower() == 'not ready': + # Setting next task to Ready, if on NOT READY + if next_task and state == 'Done': + if next_task['status']['name'].lower() == 'not ready': - # Get path to task - path = task['name'] - for p in task['ancestors']: - path = p['name'] + '/' + path + # Get path to task + path = task['name'] + for p in task['ancestors']: + path = p['name'] + '/' + path - # Setting next task status - try: - query = 'Status where name is "{}"'.format('Ready') - status_to_set = session.query(query).one() - next_task['status'] = status_to_set - except Exception as e: - self.log.warning(( - '!!! [ {} ] status couldnt be set: [ {} ]' - ).format(path, e)) - else: - self.log.info(( - '>>> [ {} ] updated to [ Ready ]' - ).format(path)) + # Setting next task status + try: + query = 'Status where name is "{}"'.format('Ready') + status_to_set = session.query(query).one() + next_task['status'] = status_to_set + except Exception as e: + self.log.warning(( + '!!! [ {} ] status couldnt be set: [ {} ]' + ).format(path, e)) + else: + self.log.info(( + '>>> [ {} ] updated to [ Ready ]' + ).format(path)) - session.commit() + session.commit() def register(session, **kw): '''Register plugin. Called when used as an plugin.'''