From 84256bd8161700b9722a00a696526ca35e79ec0b Mon Sep 17 00:00:00 2001 From: Joseph Yu Date: Wed, 10 Mar 2021 16:18:32 +0000 Subject: [PATCH] Fix when context entity "name" not cached --- python/context_selector/context_widget.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/python/context_selector/context_widget.py b/python/context_selector/context_widget.py index 921ff57a..217d538a 100644 --- a/python/context_selector/context_widget.py +++ b/python/context_selector/context_widget.py @@ -626,9 +626,18 @@ def _on_context_activated(self, context): def _on_entity_activated(self, entity_type, entity_id, entity_name): """ Slot called when an entity is selected via one of the search completers. + + Since ``context_from_entity`` doesn't guarantee "name" field to be populated, + fallback to use ``entity_name`` if it's missing. """ bundle = sgtk.platform.current_bundle() context = bundle.sgtk.context_from_entity(entity_type, entity_id) + if entity_type == "Project": + context.project.setdefault("name", entity_name) + elif entity_type == "Task": + context.task.setdefault("name", entity_name) + else: + context.entity.setdefault("name", entity_name) self._on_context_activated(context) def _on_task_search_toggled(self, checked):