As a sanity check for who come across this in the future, I’d like to note explicitly one code example that proves this point from Philip.
Note it is possible it define optional fields in a template using the square brackets syntax ([Epsiode]
) but this is only intended to make keys optional in the file name and not in the path, you would likely hit errors if you tried to make the episode field optional, so its best to have two sets of templates, episodic and non episodic.
When attempting to have an optional portion of the sequence_root
template in templates.yml
that looks like something like this:
...[/episodes/{Episode}]...
I noticed that the File Open dialog provided by tk-multi-workfiles2
no longer was able to create a new file for a particular Task context (using the + New File
button at the bottom left of the window).
Upon clicking this button, I was greeted with an error like this:
tank.errors.TankError: Cannot resolve template fields for context '<task name>, Shot <shot name>' - the following keys could not be resolved: 'Shot, Step'. Please run the folder creation for '<site shotgun url>/detail/Task/<task ID>' and try again! //
Tracing through the code lead me down this path:
- This line in new_file_action.py of tk-multi-workfiles2.
- This line in context.py of tk-core.
- This next line in context.py of tk-core.
- This final line of context.py of tk-core. This line is what is causing at least some of sgtk’s incapability to support the ability to have 1
templates.yml
that supports both episodic and non-episodic projects.
The more exact position of incompatibility lies here in template.py of tk-core. It seems that the parent
property of a TemplatePath
doesn’t function correctly when optional paths are present in the dirname
portion of a path.
For example: If I have defined a template called shot_root
like:
>>> shot_root_template = tk.templates['shot_root']
>>> print(shot_root_template)
<Sgtk TemplatePath shot_root: production[/episodes/{Episode}]/sequences/{Sequence}/shots/{Shot}>
then run
>>> template.parent
<Sgtk TemplatePath production\episodes\{Episode}\sequences\{Sequence}\shots>
Calling template.parent
bakes in the optional keys here, and doesn’t consider the ‘parent’ path of the TemplatePath without applying the optional keys in the path.
_get_template_ancestors
in context.py doesn’t account for this shortcoming of template.parent
and therefore the templates.yml
doesn’t work for both episodic and non-episodic projects.