Problem with find()'s filter

Hello,

I am discovering shotgun api and stuck in a basic issue

proj_filter = ['project', 'is', ctx.project]
assets = sg.find("Asset" , [proj_filter] , ['code', 'sg_asset_type'])

this code works as expected

proj_filter = [['project', 'is', ctx.project],['sg_asset_type', 'is' ,'character']]
assets = sg.find("Asset" , [proj_filter] , ['code', 'sg_asset_type'])

This one gives me this error :

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/s/apps/packages/mikrosVfx/vfxTkCore/0.20.16.mikros.1.3/studio/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 
1034, in find
    result = self._call_rpc("read", params)
  File "/s/apps/packages/mikrosVfx/vfxTkCore/0.20.16.mikros.1.3/studio/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 
3394, in _call_rpc
    self._response_errors(response)
  File "/s/apps/packages/mikrosVfx/vfxTkCore/0.20.16.mikros.1.3/studio/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 
3711, in _response_errors
    raise Fault(sg_response.get("message", "Unknown Error"))
tank_vendor.shotgun_api3.shotgun.Fault: API read() invalid/missing filters string 'relation' (simple condition):
{"path"=>
  "[\"project\", \"is\", {\"name\"=>\"VFX Sandbox\", \"id\"=>181, \"type\"=>\"Project\"}]",
 "relation"=>["sg_asset_type", "is", "character"],
 "values"=>[]}

When watch the doc I can’t figure what’s wrong
https://developers.shotgridsoftware.com/python-api/reference.html#filter-syntax

Thanks for your help

You are wrapping the filter again in a list. This is your problem.
sg.find("Asset" , [proj_filter] , ['code', 'sg_asset_type'])
should be
sg.find("Asset" , proj_filter, ['code', 'sg_asset_type'])

1 Like

Thanks a lot Mois !

maybe could you help me again :slight_smile:

I want to check some ‘PublishedFile’ but again I mess with the filter.

proj_filter = [['project', 'is', ctx.project],['version_number' , 'is' , 2],['sg_asset_type' , 'is' , 'vegetation']]

or

proj_filter = [['project', 'is', ctx.project],['version_number' , 'is' , 2],['asset.sg_asset_type' , 'is' , 'vegetation']]

doesn’t work when i use :

assets = sg.find("PublishedFile" , proj_filter )

I know the ‘sg_asset_type’ I want to use is a link from ‘Asset’
how can I use a linked field in my filter ?

These are called “transitive relations” in the docs I think. You want an asset to which the PublishedFile is linked. The shot/asset is in the publish’s entity field.
It would be something like
['entity.Asset.sg_asset_type', 'is', 'vegetation']

works fine !
thanks again for your explanation