how to fetch custom_attributes in a query?
1 1

8 posts in this topic

Hi,

I'm trying to figure out a query to retrieve all or selected custom_attributes in a query. I have some custom attributes on a project and my session has autopopulating turned OFF.

project = session.query('select custom_attributes from Project where name is "{0}"'.format(name)).one()

if I try to access my custom attribute "foo" the value of it is not set

print project['custom_attributes']['foo']
> NOT_SET

I tried to pass the attribute name directly to the query but that in key error

project = session.query('select custom_attributes.foo from Project where name is "{0}"'.format(name, key)).one()
> ServerError: Server reported error: KeyError(u"No attribute u'foo' exists for schema u'CustomAttributeValue'.")

is it possible to fetch custom attributes in the main query?

Share this post


Link to post
Share on other sites

 

it would be nice to have syntax like this documented in the documentation... this post is from 2016.

is this syntax used in other places too?

is there an equivalent syntax to sql `select * from bla`?

 

 

Share this post


Link to post
Share on other sites

so this syntax seems to only retriveve boolean attributes or maybe just a first boolean. When I tested it before I had only one bollean custom attribute and it seemed to work. but it fails with more

        project = session.query('select custom_attributes.value from Project where name is 1').one()
        for a in project['custom_attributes']:
            print "{0} - {1}".format(a, project['custom_attributes'][a])

        shot = session.query('select custom_attributes.value from Shot where project.name is 1').first()

        for a in shot['custom_attributes']:
            print "{0} - {1}".format(a, shot['custom_attributes'][a])

prints:

QTforWips - False
width - NOT_SET
height - NOT_SET
fps - NOT_SET

fend - NOT_SET
handles - NOT_SET
frameIn - NOT_SET
frameOut - NOT_SET
handleFrameIn - NOT_SET
handleFrameOut - NOT_SET
duration - NOT_SET
fstart - NOT_SET
fps - NOT_SET

`QtForWips` was my first test attribute and it has the value retrieved.

back to the original question. is it possible to retrieve custom attributes?

Share this post


Link to post
Share on other sites

Hi Pawel,

you should be able to fetch all the custom attributes and their values with the syntax you first suggested : 

session = ftrack_api.Session(auto_populate=False)

project =  session.query(
    'select custom_attributes.value from Project'
).first()

for key, value in project['custom_attributes'].items():
    print key, value

 

Could you check what server version and api version you are running with the code below:

import ftrack_api

session = ftrack_api.Session()

print 'ftrack version "{0}" and api version "{1}"'.format(
	session._server_information.get('version'), ftrack_api.__version__
)

 

cheers

Eric

 

 

 

 

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