Query the AssetVersion based on the links
1 1

5 posts in this topic

Hi,

I'd like to get the AssetVersion objects which belong to some TypedContext. The same way as the web interface shows the versions belonging to some tasks of a shot.

When printing out the AssetVersion members, I see there's a list of "link" items with all the path entities up to the root project in the form of {"id", "type", "name"}. This looked very promising so I've created a query:

query = "select id from AssetVersion where link any (id is {})".format(entity_id)

But this returns an error:

Quote

ftrack_api.exception.ServerError: Server reported error: TypeError('NoneType' object has no attribute '__getitem__')

I tried a million of other variations but none of them worked either. Can you suggest soemthing?

Thanks.

 

Andriy

Share this post


Link to post
Share on other sites

Hi Andriy,

The trouble is "link" is a string attribute so you need to use the like operator (https://mariadb.com/kb/en/like/):
project_tasks = session.query('Task where link like "%{}%"'.format(project['id'])).all()

Another option would be using the ancestors attribute like so:
project = session.query('Project').first()
proj_tasks = session.query('Task where ancestors any (id is "{0}") or project_id is "{0}"'.format(project['id'])).all()
 

Share this post


Link to post
Share on other sites

Hi Steve,

Thank you, this works! Is it documented somewhere? Are there any ways to see this actual data and its type?

If this is a string, how does it look like? What if I want to search just for names of the links? For example, to find all the names equal to "Shots" but not to match "Other Shots".

Thank you.

Andriy

 

Share this post


Link to post
Share on other sites

I don't know that we document the link attribute specifically, though entity types are constructed dynamically in the Python client, and the full specifications are available as session.schemas. I've developed a few convenience methods for myself, but you can query this particular attribute type via:

session.types['AssetVersion'].attributes.get('link').data_type

It gets a little weird because what we actually send over the wire, the JSON response to a query, treats it as a list of dicts. Also, there's not a fixed representation of the link (or _link or _api_link) attr in the db, so you can't really inspect how exactly the link attribute looks, nor do you really need to. Using ancestors should give you the sort of control you want.

 

Including because I found it interesting:

session.query(
	'AssetVersion where link like '
	'"%9fb3ff08-5fe5-11ea-a722-42010af00017%660cb3f7-bd3c-4cea-9afe-f38e1fe835a1"'
).one()

 

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
1 1