Jump to content

'cannot set relationship to string value' on creation (python api)


thechiclayano

Recommended Posts

Hi everyone, I'm a new user. I'm working in version 2.3.3 of the ftrack python api.

So i've been able to create tasks with the following code (this similarly applies for all entity types i've tried):

shot = session.query('Shot where name is create_test_shot').one()
task = session.create('Task', {'name':'create_test_task'})
shot['children'].append(task)
session.commit()

This works. However, a lot of other things I would expect to work don't. Here's a few examples:

shot = session.query('Shot where name is create_test_shot').one()
task = session.create('Task', {'name':'create_test_task'})
task['parent'] = shot      #This one is straight from the tutorial
session.commit()
shot = session.query('Shot where name is create_test_shot').one()
task = session.create('Task', {'name':'create_test_task', 'parent':shot})
session.commit()
shot = session.query('Shot where name is create_test_shot').one()
task = session.create('Task', {'name':'create_test_task', 'parent_id':shot['id']})
session.commit()
shot = session.query('Shot where name is create_test_shot').one()
task = session.create('Task', {'name':'create_test_task'})
shot['children'].append(task)
task['type'] = 'animation'
session.commit()

All of these fail with the same error when I attempt to commit (using the same data and a fresh session in each case):

Server reported error: ValueError(Cannot set relationship to string value.)
Nonetype: None

Any ideas on what i'm doing wrong?

Link to comment
Share on other sites

  • 2 weeks later...

Hi @thechiclayano,

This is an interesting problem because, unfortunately, I'm not seeing the same behaviour as you are. 

First off, I'm assuming that between each session you'd make sure that the task with the name `create_test_task` didn't exist under shot `create_test_shot` prior to your trying to create it. I think this is a safe assumption because otherwise, you should get an `IntegrityError`, not a `ValueError`.

Given that assumption, I tried reproducing your code against my site via an ipython session, and this is what I got:

In [4]: ftrack_api.__version__
Out[4]: '2.3.3'

In [5]: session = ftrack_api.Session()

In [6]: shot = session.query("Shot where name is create_test_shot_02").one()

In [7]: task = session.create("Task", {"name": "create_test_task"})

In [8]: shot["children"].append(task)

In [9]: session.commit()

In [10]: task = session.create("Task", {"name": "create_test_task_02"})

In [11]: task["parent"] = shot

In [12]: session.commit()

No errors.

Then I figured, maybe it was because you were doing it in multiple independent sessions so I quit ipython, started it back up again, and tried the last portion of the example code, changing the task name as to avoid the `IntegrityError`:

In [4]: ftrack_api.__version__
Out[4]: '2.3.3'

In [5]: session = ftrack_api.Session()

In [6]: shot = session.query("Shot where name is create_test_shot_02").one()

In [7]: task = session.create("Task", {"name": "create_test_task_03"})

In [8]: task["parent"] = shot

In [9]: session.commit()

Again, no errors.

When I focused on the quoted error message:

Server reported error: ValueError(Cannot set relationship to string value.)

I noticed that your last change to the task was setting the `type` attribute to the value `'animation'`. This won't work and will indeed cause the above error. I can easily reproduce this:

In [16]: task["type"] = "animation"

In [17]: session.commit()
Server reported error: ValueError(Cannot set relationship to string value.)
NoneType: None

What's happening is that a task's type is an actual object. You can query `Type` objects in ftrack like any other object type. For example:

In [25]: task = session.query("Task where name is create_test_task_03").one()

In [26]: task["type"]
Out[26]: <dynamic ftrack Type object 4625836160>

In [27]: task["type"]["name"]
Out[27]: 'Texture'

In [28]: animation_type = session.query("Type where name is Animation").one()

In [29]: task["type"] = animation_type

In [30]: session.commit()

So what this all boils down to is that the error you put in your message is legit but points to the small mistake in setting the task type in the last example but I can't reproduce the problem with the first example you say doesn't work.

If this is still a problem for you, could you provide the error you get for the first problematic example?

Cheers,
Patrick

Link to comment
Share on other sites

  • 3 weeks later...

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