Querying and/or reviving deleted fields through the python API?

I’m pretty new to Shotgun. Forgive me if this has been answered.

We have a use case where it’s possible that an entity’s field would get deleted through python script, and then created again. As it stands, this throws an error:

# Error: line 1: Fault: file C:\CC\Tools\bxExternal\devs\autodesk\shotgun\python2x\shotgun_api3\shotgun.py line 3464: API schema_field_create() failed, there is a retired field with the same field_name: sg_test_field. Delete the retired field forever from the Trash Page in Shotgun and try again. # 

To get around that, I would expect to be able to query whether a field has been ‘retired’ and then ‘revive’ it instead of creating it. I can’t find any documentation on how this would work through the API.

Thanks,
-Jake

1 Like

Hi Jake,

It is a very good question. You could read this find retired. And use this to revive.

Cheers

Loney

2 Likes

Thank you for your response, but I’m still not sure how to query retired fields on an entity. Unless I’m misunderstanding, Shotgun.find() and Shotgun.revive() only work on entities, not fields.

Can you give me an example script?

1 Like

@jing.liu I was advised by our developer support contact at Autodesk to submit a support ticket for this. If I get a workable solution, I’ll post it here.

1 Like

Posting a followup:
It looks like this is officially unsupported through the API.
Even to perform this action through the UI, you need admin permissions, so it’s unsurprising that it can’t be scripted.
The workaround we’ve discussed internally is to periodically generate a list of deprecated fields and have a human (with admin permissions) perform the cleanup.

1 Like

Hi Jake,

Find doesn’t work field entity. If would be a new feature for schema_read_field to get retired field. Very appreciate if you could request here

Thanks

Loney

2 Likes