Hello,
I'm writing an event plugin that when a task status is changed the shot status will match. It works on the first change however if you change it to something else it still gets the original status. For example....
Change animation from "on hold" to "in progress" will change the status of the shot to "in progress". Change it to "approved" it will still set it as "in progress".
Is there something that can be done to get the updated status? This is my code:
def cascade_status_changes_event_listener(session, event):
'''Handle *event*.'''
user_id = event['source'].get('user', {}).get('id', None)
status_changed = False
entities = event['data'].get('entities', [])
for entity in entities:
entity_id = entity['entityId']
shot = session.query(
'select status_id, status.name from Shot '
'where children any (id is "{0}")'.format(entity_id)
).first()
if shot:
# get the task name that its been set to
query = f'Task where id is {entity_id}'
task = session.query(query).one()
task_status_name = task['status']['name']
project = shot['project']
schema = project["project_schema"]
shot_statuses = schema.get_statuses(schema='Shot')
for status in shot_statuses:
if status['name'] == task_status_name:
shot['status_id'] = status["id"]
status_changed = True
break
else:
logger.info('No shot found, ignoring update')
if not status_changed:
return
# Persist changes
try:
session.commit()
except Exception:
logger.exception('Failed to update status')
# Since we failed to synchronize our changes with the server, revert
# our state to match what was on the server when we started.
session.rollback()
raise
Thanks!