diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/data_stores/json.py b/spiffworkflow-backend/src/spiffworkflow_backend/data_stores/json.py index 60a85982a..87e108d92 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/data_stores/json.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/data_stores/json.py @@ -27,15 +27,17 @@ def _data_store_exists_at_location(location: str, identifier: str) -> bool: return FileSystemService.file_exists_at_relative_path(location, _data_store_filename(identifier)) -def _data_store_location_for_task(spiff_task: SpiffTask, identifier: str) -> str | None: +def _data_store_location_for_task(spiff_task: SpiffTask, identifier: str, check_disk: bool) -> str | None: location = _process_model_location_for_task(spiff_task) if location is None: return None if _data_store_exists_at_location(location, identifier): return location location = ReferenceCacheService.upsearch(location, identifier, "data_store") - # if location is None or not _data_store_exists_at_location(location, identifier): - # return None + if location is None + return None + if check_disk and not _data_store_exists_at_location(location, identifier): + return None return location @@ -76,7 +78,7 @@ def build_response_item(model: Any) -> dict[str, Any]: def get(self, my_task: SpiffTask) -> None: """get.""" model: JSONDataStoreModel | None = None - location = _data_store_location_for_task(my_task, self.bpmn_id) + location = _data_store_location_for_task(my_task, self.bpmn_id, False) if location is not None: model = db.session.query(JSONDataStoreModel).filter_by(identifier=self.bpmn_id, location=location).first() if model is None: @@ -85,10 +87,13 @@ def get(self, my_task: SpiffTask) -> None: def set(self, my_task: SpiffTask) -> None: """set.""" - location = _data_store_location_for_task(my_task, self.bpmn_id) + location = _data_store_location_for_task(my_task, self.bpmn_id, False) if location is None: raise Exception(f"Unable to write to data store '{self.bpmn_id}' using location '{location}'.") data = my_task.data[self.bpmn_id] + + # TODO: validate data against schema + model = JSONDataStoreModel( identifier=self.bpmn_id, location=location, @@ -127,7 +132,7 @@ class JSONFileDataStore(BpmnDataStoreSpecification): # type: ignore def get(self, my_task: SpiffTask) -> None: """get.""" - location = _data_store_location_for_task(my_task, self.bpmn_id) + location = _data_store_location_for_task(my_task, self.bpmn_id, True) if location is None: raise Exception(f"Unable to read from data store '{self.bpmn_id}' using location '{location}'.") contents = FileSystemService.contents_of_json_file_at_relative_path(location, _data_store_filename(self.bpmn_id)) @@ -135,7 +140,7 @@ def get(self, my_task: SpiffTask) -> None: def set(self, my_task: SpiffTask) -> None: """set.""" - location = _data_store_location_for_task(my_task, self.bpmn_id) + location = _data_store_location_for_task(my_task, self.bpmn_id, True) if location is None: raise Exception(f"Unable to write to data store '{self.bpmn_id}' using location '{location}'.") data = my_task.data[self.bpmn_id]