Jump to content

How to query current AssetVersion from ftrack new API


dheeraj.bana

Recommended Posts

Hi Guys,

how to query current AssetVersion from ftrack new API?

I am using below mentioned command, that returns all the versions. but i don`t know which one is latest.

 asetVer = session.query('AssetVersion where asset.parent.id is "f0674960-3496-11e6-98b0-02420a5c000c" and asset.type.short is "geom" and asset.name is "geom"').all()

Link to comment
Share on other sites

1 hour ago, dheeraj.bana said:

how to query current AssetVersion from ftrack new API?

You mean the current as in "the latest published one"? At the moment it is not possible so you will have to resort to loading the version number / publish date and sort.

I wonder if it would be handy to have that as a relation on the asset? E.g. session.query('select latest_version from Asset where ...'). Or perhaps better on the asset version as "is_latest"?

Note: I moved this discussion to a new thread.

Link to comment
Share on other sites

Thanks for quick response. Exactly that`s what i was asking for :)

Yes we can tag new version as a latest_version, but when we will create new version then we will have to untag (i.e. reset) the older versions, correct?

If correct, then its better to sort the versions and get the latest version rather than creating new attribute/tag (to get/set latest version)

22 minutes ago, Mattias Lagergren said:

At the moment it is not possible so you will have to resort to loading the version number / publish date and sort.

so when can this feature be available ?

Link to comment
Share on other sites

Answered via another channel, but including my response here for future reference.

The version number attribute is called `version`, and you also have a `date` attribute available. You can use that in your query to filter on the latest version.

 

If you want the single latest version:

asetVer = session.query(
    'AssetVersion where asset.parent.id is "f0674960-3496-11e6-98b0-02420a5c000c"'
    ' and asset.type.short is "geom" and asset.name is "geom"'
    ' order by date desc'
).first()

 

If you want the latest version of all assets it gets a bit more complicated. You can currently not order or limit relationships or group the results. As a workaround you can group the returned versions in the client. Here is an example of how you could do it.

asset_versions = session.query(
    'select asset_id, version'
    ' from AssetVersion where asset.parent.id is "f0674960-3496-11e6-98b0-02420a5c000c"'
    ' and asset.type.short is "geom" and asset.name is "geom"'
)

latest_versions = {}
for asset_version in asset_versions:
    asset_id = asset_version['asset_id']
    max_version = latest_versions.get(asset_id, {}).get('version', 0)
    if asset_version['version'] > max_version:
        latest_versions[asset_id] = asset_version

for asset_id, asset_version in latest_versions.iteritems():
    print ' / '.join([item['name'] for item in asset_version['link']])

 

@Mattias Lagergren, exposing a `latest_version` relationship would be an interesting way to solve the second situation in the future without having to resort to client-side filtering and grouping.

 

Regards,
Lucas

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...