I’ve got a custom query type field created for the Shot entity. When I try to get the value of that field using the Shotgun Python API (shotgun.find_one with the field name in the fields argument), it always comes back as None, even though it has a value on the Shotgun site. Is fetching query field values possible and if so - how is it done?
First, be sure to use the right field name:
On a shot page, display the searched column, right clic on the header, configure field and there you’ll see the Field code. It’s usually different from the displayed name.
Then you can query this field like any other.
If this doesn’t help, please post your code. It will be easier to spot the issue.
If you’re referring to re-creating the query for the version using the Python API - I already figured I could do that, but it’s just an extra step. I was hoping could be avoided, since the field on Shotgun should already contain a value or at least I hoped it could be forced to calculate the value for you in the response.
Summary type fields like Query Fields and Pipeline Step summary fields are currently only available via the UI. Some other fields may not work as expected through the API because they are “display only” fields made available for convenience and are only available in the browser UI.
You can retrieve the configuration of a query field via the API using sg.schema_field_read and then pass that config into an sg.find or sg.summarize call.
In your case, you’d do: my_field_config = sg.schema_field_read('Shot', 'sg_latest_version_for_delivery')['sg_latest_version_for_delivery']
Then the configuration of the query field, including the filters and the intended format of the result, will be available as a dict in: my_field_config['properties']
You’d then need to pop keys out of that result and stuff them into an sg.summarize() call.
This general approach avoids having to duplicate your query config in your client code, allowing you to reconfigure the query field in the UI and have your code continue to work with it without having to refactor.
I had to build a solution to this problem with a project that I was working on recently. I remembered coming accross this thread and thought I would share what I came up with. I did my best to package up the functionality that I thought would be helpful to other developers.
Importing this package will give you access to new versions of the find and find_one methods you would traditionally use with the ShotGun class.
How it works
After executing the relative find method, I check if any of the fileds requested are query fields. I then use the entity schema to construct additional queries and return the query values with the rest of the results. My goal was to make using these find functions as seamless as possible with the way they work now.
Expect these new methods to be slower than the standard find methods because of all the extra queries that need to be made, so please keep that in mind.
Feel free to reach out to me if you have any questions or suggestions.
Semi-related, have you at all attempted to pull data from PageSettings to inspect filters in the web and then attempted to translate them at all? I haven’t done this myself but this repo is a good excuse to add this as another feature. Will let you know if I fork this and get something working but it won’t be anytime soon unfortunately…!
Unfortunately, I haven’t had to deal with pages as all, but I am curious on how similar the process might be. I was juest testing requesting a few pages directly from the API and I am not seeing any filter information being retruned. Have you been able to retrieve that info?
I am using the GET /api/v1/entity/pages/:id and the GET /schema/pages/fields routes.