mikedatsik Posted February 22, 2018 Report Share Posted February 22, 2018 Hi all! This returns me all available version: task = session.get('Context', 'some-id') versions = session.query('AssetVersion where task_id is "{0}"'.format(task['id'])).all() I need to get only the latest versions. Is it possible? L Smallwood 1 Link to comment Share on other sites More sharing options...
Eric Hermelin Posted February 22, 2018 Report Share Posted February 22, 2018 Hi, you could order by the version attribute ie. asset_version = session.query( 'select version from AssetVersion where task_id is "{0}" order by version desc'.format( 'ecac0828-4d0a-11e7-953e-0a580aa00899' ) ).first() cheers Eric Link to comment Share on other sites More sharing options...
mikedatsik Posted February 22, 2018 Author Report Share Posted February 22, 2018 Thanks for you reply! But I mean that I need latest versions for all assets in the task with one query session. Link to comment Share on other sites More sharing options...
Martin Pengelly-Phillips Posted February 23, 2018 Report Share Posted February 23, 2018 18 hours ago, postmodern said: Thanks for you reply! But I mean that I need latest versions for all assets in the task with one query session. Not possible at present to do in one query. Are you wanting to do it in one query for performance reasons? The API does support batching calls under the hood, but it doesn't seem to be implemented for queries yet. There are some TODOS in the code though... def _query(self, expression): '''Execute *query* and return (records, metadata). Records will be a list of entities retrieved via the query and metadata a dictionary of accompanying information about the result set. ''' # TODO: Actually support batching several queries together. # TODO: Should batches have unique ids to match them up later. batch = [{ 'action': 'query', 'expression': expression }] Link to comment Share on other sites More sharing options...
mikedatsik Posted February 23, 2018 Author Report Share Posted February 23, 2018 Yes, I want do it for performance reasons. I will need to get a list of version for all assets in task groped by assets. I did it something like that: import ftrack_api from itertools import groupby session = ftrack_api.Session() entity = session.get('Context', '376a3498-1191-11e8-8917-001e582bf738') assets = session.query( 'select asset.name, version from AssetVersion ' 'where task_id is "{0}" and asset.name is_not ' 'none order by version desc'.format( entity['id'])).all() res = [{"asset":l, "versions":list(v)} for l,v in groupby( sorted(assets, key=lambda x:x['asset']['name']), lambda x: x['asset']['name'])] But usually I working only with latest ones and rarely with previous. So in that reason I thought that's will be great to get only latest versions and how to get this list in best performance way. Link to comment Share on other sites More sharing options...
Chandler Posted February 20, 2020 Report Share Posted February 20, 2020 I know this is old AF, but I had this need, and Lucas kindly informed me in the Slack channel that a 'is_latest_version' property will be available in Studio 4.4 That'll be a welcome addition. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now