0

What determines the default fields in find()?

The documentation says:

"""

When you do a find() that returns a field of type entity or multi-entity (for example the 'assets' column on Shot), the entities are returned in a standard hash (dict) format:

    {'type':'Asset', 'name':'redBall', 'id':1}

"""

...but then also says that `name` isn't necessarily a valid field name (it's usually actually the `code`). 

How can I check with the API what field is being returned as 'name' for any given Entity? 

댓글 7개

  • 0
    Avatar
    Ben Zenker

    Ryan, you can find the entire schema of any entity by calling 

    schema_field_read(string entity_typestring field_namedict project_entity)

    and ignoring the "field_name".

    Once you know the keys of the fields you are interested in, you can place those keyNames into your find > returning_fields

    https://github.com/shotgunsoftware/python-api/wiki/Reference%3A-Methods#schema_field_read

  • 0
    Avatar
    Ryan de Kleer

    I know I can use the schema_field_read to get the list of fields; but that's not the issue.

    The issue is that, by default, find() will return `id`, `type` & `name`, where `name` may or may not be the actual name of the field (often it's actually the `code` field).

    What I want to know is which field is being returned as `name`?  Is it "name"? "code"?  Something else?  It varies from entity to entity, but I can't find where that relationship is defined.

    @BenZenker: the code formatting is hidden under the paragraph styles button [ ¶ ]

  • 0
    Avatar
    Ben Zenker

    The default return of find() is

    {'type': entity_type, 'id': entity_id}

    There is no 'name' field returned by default, so you might want to double-check where you are calling your find().

    From every entity I have delt with, the key for a item's name is 'code'. The ONLY case where this has been different for me is the key for a Project Name, which is 'name'. To me it appears that unless you created a custom field with the key of 'name' in your Entity, it should be 'code' by default. Where else have you found 'code' not being used?

  • 0
    Avatar
    Ryan de Kleer
    sg = # instance your shotgun connection here
    results = sg.find_one('Asset', filters=[['id', 'greater_than', 300]], fields=['project'])

    Produces:

    {'project': {'type': 'Project', 'id': 65, 'name': 'DemoAnimationProject'}, 'type': 'Asset', 'id': 726}

    Where "name" refers to the name field in the asset's project field, while:

    sg.find_one('Task', filters=[['id', 'greater_than', 20]], fields=['entity'])

    Produces:

    {'type': 'Task', 'id': 156, 'entity': {'type': 'Asset', 'id': 726, 'name': 'Buck'}}

    where 'name' is actually the Asset's "code".  Further:

    sg.find_one('Asset', filters=[['code', 'is', 'Buck']], fields=['tasks'])

    Produces:

    {'tasks': [{'type': 'Task', 'id': 156, 'name': 'Art'}, 
               {'type': 'Task', 'id': 157, 'name': 'Model'}, ...],
     'type': 'Asset', 'id': 726} #

    where "name" is actually the Task's "content" field.

     

    The point is, as in the original post, the docs themselves admit that the "name" field in such queries isn't necessarily a valid field.  What I'd like to know is where the field that is shown as "name" is determined.  I would have expected it to be in the entity's schema maybe as a "display name" or "alias" or something, but I haven't come across anything helpful yet.

     

  • 0
    Avatar
    Ben Zenker

    Wow, that's quite the setup. I think I might understand what you're asking about.

    If you go to any entity page, and select the Fields dropdown, then Configure Fields, you can hover to view the programmatically correct name for any field of information.

    Does this help?

  • 0
    Avatar
    Ryan de Kleer

    No, that's different again -- those are just the field aliases for the UI (which incidentally you can get from the schema --> [field_name]['name']['value'])

  • 0
    Avatar
    Ryan de Kleer

    Just wanted to bump this question.  It would still be great to have an answer ;)

댓글을 남기려면 로그인하세요.