Getting an outdated status through link
2 2

2 posts in this topic

Hi ,

I'm basing my code on this cascade status changes hook: https://bitbucket.org/ftrack/ftrack-recipes/src/master/python/events/cascade_status_changes/hook/status_listener_hook.py
I have the following function that I use to update the status of an "Asset Configuration" entity automatically, it returns the status of the "from entity" of an incoming link:

asset_configuration_states = ['IN_PROGRESS', 'NOT_STARTED', 'CANCELLED', 'DONE']
def get_state_name_asset_configuration(link):
    '''Return the short name of *link*'s state, if valid, otherwise None.'''
    try:
        state = link['from']['status']['state']['short']
        print link['from']['name']
        print state
    except KeyError:
        logger.info(u'Child {} has no status'.format(
            ftrack_api.inspection.identity(link['from'])
        ))
        return
    if state not in asset_configuration_states:
        logger.warning(u'Unknown state returned: {}'.format(state))
        return
    return state

If all the links return DONE then I also update the Asset Configuration to DONE. It seems however that sometimes this function returns the old state of these "from entities" and not the new updated one.

An example:
I have an "Asset Configuration" entity with 5 incoming links. 4 of these incoming links have as status DONE, and I change the status of the 5th incoming link from IN_PROGRESS to DONE as well. This triggers the call of the get_state_name_asset_configuration() function which should now only return DONE for all the incoming links, however the 5th link still has as its state IN_PROGRESS.

I have a similar function for a Shot that checks the status of its sub-tasks just like in the status_listener_hook.py file, and that one works when checking the status of a task. Is the problem that I'm checking the status through a link, and this isn't updated yet at the time of checking? If so is there a way to force them to update before I call this function?

Edit: after doing some testing it seems to me that Tasks do return their correct status, but entities like Folders/Shots/Sequences do not (they still return their old non updated Status)?

Share this post


Link to post
Share on other sites

Hi Fernando,

 

Is it possible you have cached the old value for the status? You could clear the cached value and query again to ensure that you're getting the latest value from the server.  See these two lines I've added above your "state = . . ." line.

del link['from']['status']
link.session.populate(link['from'], 'status')
state = link['from']['status']['state']['short']

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
2 2