Skip to content

session.ensure does not take dynamic ftrack objects #41

@beatreichenbach

Description

@beatreichenbach

Hello,
I'm getting this error when trying to use session.ensure with dyanmic ftrack objects:

DEBUG:ftrack_services.actions.structure:Ensure Task: {'name': 'Layout', 'type': <dynamic ftrack Type object 140688002330896>, 'parent': <dynamic ftrack Shot object 140688002473936>}
ERROR:ftrack_api.session.Session:Server reported error: UnexpectedToken(Unexpected token Token('LESSTHAN', '<') at line 1, column 76.
Expected one of: 
	* /"<[a-zA-Z0-9_\-]+>"/
	* FLOAT
	* /[a-zA-Z0-9_\/\-]+/
	* INTEGER
	* NONE
	* /"[^"]*"/
	* /'[^']*'/
	* LPAR
Previous tokens: [Token('IS', 'is')]
)
NoneType: None

This is expected as the docstring says:

        Each key should be a string.

        .. note::

            Currently only top level scalars supported. To ensure an entity by
            looking at relationships, manually issue the :meth:`query` and
            :meth:`create` calls.

The documentation mentions that data is the same as passed to create. This is true for the create portion of the code, but when querying the expression is not built properly:

data = {'name': 'Layout', 'type': <dynamic ftrack Type object 140688002330896>, 'parent': <dynamic ftrack Shot object 140688002473936>}

For example, instead of the current expression, something like the below would probably be needed:

f"where parent is {entity}"
f"where parent_id is {entity['id']}"

I think it would be great to support dynamic ftrack objects so I'm wondering what would need to happen to implement this?
Could I do something along the lines of (pseudo code):

if isinstance(value, dynamic ftrack object):
    key = f'{key}_id'
    value = value['id']

Would something like this make sense, if I catch all the errors for attributes not existing etc? Are there any other reasons this isn't supported yet by ftrack-api? Would this be something that could merged if I submit a PR?

Thanks,
Beat

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions