Prevent KeyError for optional data store writes (#1700)

This commit is contained in:
jbirddog 2024-06-10 11:17:41 -04:00 committed by GitHub
parent 5713cf50dc
commit 9b8ceb4af8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 0 deletions

View File

@ -69,6 +69,8 @@ class JSONDataStore(BpmnDataStoreSpecification, DataStoreCRUD): # type: ignore
def set(self, my_task: SpiffTask) -> None:
"""set."""
if self.bpmn_id not in my_task.data:
return
model: JSONDataStoreModel | None = None
location = self.data_store_location_for_task(JSONDataStoreModel, my_task, self.bpmn_id)
@ -127,6 +129,8 @@ class JSONFileDataStore(BpmnDataStoreSpecification): # type: ignore
def set(self, my_task: SpiffTask) -> None:
"""set."""
if self.bpmn_id not in my_task.data:
return
location = self._data_store_location_for_task(my_task, self.bpmn_id)
if location is None:
raise DataStoreWriteError(f"Unable to write to data store '{self.bpmn_id}' using location '{location}'.")

View File

@ -114,6 +114,8 @@ class KKVDataStore(BpmnDataStoreSpecification, DataStoreCRUD): # type: ignore
my_task.data[self.bpmn_id] = getter
def set(self, my_task: SpiffTask) -> None:
if self.bpmn_id not in my_task.data:
return
location = self.data_store_location_for_task(KKVDataStoreModel, my_task, self.bpmn_id)
store_model: KKVDataStoreModel | None = None

View File

@ -43,6 +43,8 @@ class TypeaheadDataStore(BpmnDataStoreSpecification, DataStoreCRUD): # type: ig
def set(self, my_task: SpiffTask) -> None:
"""set."""
if self.bpmn_id not in my_task.data:
return
typeahead_data_by_category = my_task.data[self.bpmn_id]
for category, items in typeahead_data_by_category.items():
db.session.query(TypeaheadModel).filter_by(category=category).delete()