Jump to content

Multiple schemas error on status in projection query?


Mark Stewart

Recommended Posts

So I'm new to Ftrack, and just learning about tuning projections in queries to gain a little more speed, and came across an error trying to get status.name for assigned task from a user. I get this error;

KeyError("Multiple schemas [u'Project', u'TypedContext'] found for relationship u'status'.")

I'm sure there's a way to focus on a single schema, but I'm unsure how to write it.

Can someone point me in the right direction?


Here's the existing query with the broken item in strikethrough;
user = session.query(
            'select \
            assignments.context._link, \
            assignments.context.name, \
            assignments.context.parent.name, \
            assignments.context.status.name, \
            assignments.context.parent.parent.name from User \
            where is_active is "True" and email is "{}"'.format(user_email)).one() 

Less of a concern for me, but another question is, can I select an index in a list? I only want the first item in assignments.context._link.
Thanks!

M.
 

Link to comment
Share on other sites

Hi Mark,

I'm not sure you can do that with a projection, at least at the moment. When using an attribute like that as a condition, you need to cast the value to a specific entity type. We mention it in passing here. I'll have to check with someone who's more experienced with that part of the code base to see whether it's (intended to be) possible to do it the way you're thinking about.

However, it appears you're trying to get information on a users assigned Tasks (or TypedContexts, but probably just Tasks, right?), correct? You could run the query using a subquery (mentioned here):
 

projections = ', '.join((
    '_link',
    'name',
    'parent.name',
    'status.name',
    'parent.parent.name',
))
assigned_tasks = session.query(
    f'select {projections}'
    ' from TypedContext where id in'
    f' (select context_id from Appointment where resource.email is "{user_email}")'
).all()


For the second question, regarding "_link": No, you cannot receive only part of the response back, but the first part of _link is Project information, so you could query for that specifically. You just need "project.name" since you'll always get the primary key(s), which is usually just "id". Alternately, if all you care about are names, you could change the projections to:

projections = ', '.join((
    'ancestors.name',
    'status.name',
))

 

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