Skip to content

Commit

Permalink
add SafeDict class to handle missing keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Fricard committed Oct 16, 2023
1 parent d0ac4f7 commit ee1ca5e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion openpype/modules/deadline/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import os
import re

from openpype.settings import get_current_project_settings


class SafeDict(dict):
def __missing__(self, key):
return '{' + key + '}'


def set_custom_deadline_name(instance, filename, setting):
context = instance.context
basename, ext = os.path.splitext(filename)
Expand All @@ -28,7 +34,7 @@ def set_custom_deadline_name(instance, filename, setting):
}

custom_name_settings = get_current_project_settings()["deadline"][setting] # noqa
custom_name = custom_name_settings.format(**formatting_data)
custom_name = custom_name_settings.format_map(SafeDict(**formatting_data))

for m in re.finditer("__", custom_name):
custom_name_list = list(custom_name)
Expand Down

0 comments on commit ee1ca5e

Please sign in to comment.