Jump to content

how to edit custom atributtes


Eder Agreda

Recommended Posts

Hello. I got an issue I hope you could help me with.

I have a task with 2 custom atributtes and I want to change one of these via a python script.

According to documentation I have 2 options:

task['custom_attributes']['my_text_field'] = 'foo'
task['custom_attributes'] = {
    'my_text_field': 'bar'}

If I use the first one, it doesn´t update the info  and if I use the second one, it works but generates a warning for the other custom atributte I am not setting

To be precise:

 my task got 2  custom atributtes: lastVersion and retakes.I want to update lastVersion so I do this:

task['custom_attributes']['lastVersion'] == value

And it doesn't do anything. So I tried the second option:

task['custom_attributes'] = {
    'lastVersion': value}

This one works but I got an annoying warning:

WARNING:ftrack_api.collection.CustomAttributeCollectionProxy:Cannot delete u'retakes' on <dynamic ftrack Task object 192507688>, no custom attribute value set.

 

 

 

 

Link to comment
Share on other sites

Hi Eder, it is definitely the first approach you should use and it sounds like a bug if it doesn't work. The second approach will overwrite all custom attributes:

task['custom_attributes'] = { 'my_text_field': 'bar'}

If you use the first approach, nothing happens? Can you try with other entities / custom attributes.

Link to comment
Share on other sites

15 hours ago, Eder Agreda said:

Hello.Aparently It was an error with that entity.I tried in another one and It works fine.

Cool - please let me know if you find out what the problem was with this entity. Sounds like a potential bug; if something is wrong it should error with a message and not just silently drop your changes.

Link to comment
Share on other sites

  • 3 weeks later...

Hello. well I got an error again with another task.Its kind of wierd: I have a shot with  2 taks: model and shading.If I try to  change custom attribute in shading It does it without issues but If I try   in the model task I got an AssettionError:

 

AssertionError.JPG

the Code I´m trying is:

 

#task =session.query("Task where name is 'shading' and parent.name is 'condoChair'  and parent.parent.name is 'props'").first()  #this one works

#task =session.query("Task where name is 'model' and parent.name is 'condoChair'  and parent.parent.name is 'props'").first()  # this one generates error


task['custom_attributes']['lastVersion'] = 1
fo.session.commit()
print "version modified to: {0} ".format(1)

Greetings!

Link to comment
Share on other sites

Yes, I have fo.session for not needing to write user, url and apikey  everytime I need to test something.

About the tasks, they are both in the same project, they  were created the same day, the same way and they also shared the same parent. The only difference I could recall besides taskType is that shading("the one that works") has no bidding value while "model"(that one that doesn´t work does ).

 

Greetings

Link to comment
Share on other sites

I am having a similar issue with custom attributes at the project level. What I am finding is that it is possible to set new values for the custom attribute indefinitely until I use a get method to extract the value that has been set. Once a get method is called, the custom attribute value is frozen in place. However, this only happens upon calling the session commit (judging from my debug session).

So let's say my set and get methods look like this:

def setLocations(self, ent, locs):
	# locs is a list of locations
    # ent is a project
	# all locs are vetted against options in the locations enumerator first
    
	ent['custom_attributes']['locations'] = locs
	self.session.commit()

@staticmethod
def getLocations(ent):
	locs = ent['custom_attributes']['locations']
  	return locs

And suppose I have a unit test for the functions above. Here are 2 alternate versions of the unit test (obviously, the first one passes and the second one fails):

def test_passes(self):
	locs1 = ["mars", "venus"]
	locs2 = ["mars", "jupiter", "venus"]
	locs3 = ["mars", "jupiter", "venus", "mercury"]

	api.setLocations(my_proj, locs1)
	api.setLocations(my_proj, locs2)
	api.setLocations(my_proj, locs3)
	
	proj_locs = api.getLocations(my_proj)

	self.assertEqual(proj_locs, locs3)

def test_fails(self):
	locs1 = ["mars", "venus"]
	locs2 = ["mars", "jupiter", "venus"]
	locs3 = ["mars", "jupiter", "venus", "mercury"]

	api.setLocations(my_proj, locs1)
	proj_locs1 = api.getLocations(my_proj)

	api.setLocations(my_proj, locs2)
	proj_locs2 = api.getLocations(my_proj)
	
	api.setLocations(my_proj, locs3)
	proj_locs3 = api.getLocations(my_proj)

	self.assertEqual(proj_locs1, locs1)
	self.assertEqual(proj_locs2, locs2)
	self.assertEqual(proj_locs3, locs3)

When I run this through pdb, everything appears to be setting correctly until I pass the commit line in setLocations (i.e. if I check the value of ent['custom_attributes']['locations'] after setting it but before committing it). Then the getLocation returns the first entry. Thoughts?

Link to comment
Share on other sites

Thank you for reporting this issue. I have verified the issue and added a failing unit test to the API and added a ticket to follow up and fix the issue.

The underlying cause seems to be an issue with the caching of enumerator custom attributes. To work around the issue, you can reset the session before the changing the value, like so:

session.reset()
entity['custom_attributes'][attribute_key] = test_value_two
session.commit()
assert entity['custom_attributes'][attribute_key] == test_value_two

Note that this has some side effects - any pending operations will be lost, the cache will be cleared and locations will be reconfigured. See more info in API reference.
 

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...