Jump to content

session cache update


Recommended Posts


I was working on a event action script. It is used to collect all notes under one assetVersion and convert them to a doc which will be added to a new note.

It works fine at first. But I found that it can not collect new notes which are created after the starting time of the event script. So I think the problem may be the session cache.

Then I add a code to clear the session: session.cache.clear() at lunch function. But error shows up:

ERROR:ftrack_api.event.hub.EventHub:Error calling subscriber <Subscriber metadata={'id': '723b56730bde4abe81f3c732303f2e9f'} subscription="topic=ftrack.action.launch and data.actionIdentifier=sy.notes-to-docx"> for event <Event {'topic': u'ftrack.action.launch', 'source': {u'id': u'6347029859d2401bb850f5fada92295c', u'user': {u'username': u'chengshun', u'id': u'bcdf57b0-acc6-11e1-a554-f23c91df1211'}}, 'target': u'', 'data': {u'actionIdentifier': u'sy.notes-to-docx', u'selection': [{u'entityId': u'ac013aa4-9065-11ea-bda8-0a58ac1e069e', u'entityType': u'assetversion'}], u'label': u'Notes To Docx'}, 'in_reply_to_event': None, 'id': u'32a6a71deed7415f9e9f9b35277c30ac', 'sent': None}>.
Traceback (most recent call last):
  File "c:\Python27\lib\site-packages\ftrack_api\event\hub.py", line 724, in _handle
    response = subscriber.callback(event)
  File "D:\git\shenyin_pipeline\ftrack\export_notes_to_doc.py", line 98, in launch
  File "c:\Python27\lib\site-packages\ftrack_api\session.py", line 1956, in create_component
    'FileComponent', path, data, location
  File "c:\Python27\lib\site-packages\ftrack_api\session.py", line 2025, in _create_component
    origin_location.add_component(component, path, recursive=False)
  File "c:\Python27\lib\site-packages\ftrack_api\entity\location.py", line 78, in add_component
    [component], sources=source, recursive=recursive
  File "c:\Python27\lib\site-packages\ftrack_api\entity\location.py", line 139, in add_components
LocationError: No structure defined for location <Location(ce9b348f-8809-11e3-821c-20c9d081909b)>.

And the error comes from the code session.create_component()

I use cache.clear() at another event action script to create folders at the studio network storage and it works fine. Seems like only create function will go wrong after cache.clear().

I put the full script below.

Need some help, thanks.





Edited by Lorenzo Angeli
removed file with sensible informations
Link to comment
Share on other sites

Hi @chengshun resetting the cache half way through the action is risky at least.

Something you can try is to rework the query you are doing as such:

  entity_ins = self.session.query('select notes from AssetVersion where id is %s' %  sel_id).first()

here you can find one of our examples which shows you how to use the use of ftrack-action-handler and how to attach the result document to the job itself ,so you don't have to save it , hope it helps.
if you are still having issues please let us know.


Link to comment
Share on other sites

Thanks, Lorenzo

I'm sorry but It doesn't work.

I tried the session.populate(project, 'notes'), but the result is same as not using the code, just like before when I didn't add cache.clear(). Newly created notes were removed.

Seems like the session data is not updated.

The code I've changed is like below:


Link to comment
Share on other sites

  • 4 weeks later...
del asset_version['notes']
session.populate(asset_version, 'notes')

This missing piece here was clearing the cached value of the collection attribute.

Link to comment
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
  • Create New...