Validate writes to the json data store against its schema (#875)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Kevin Burnett <18027+burnettk@users.noreply.github.com>
This commit is contained in:
jbirddog 2024-01-24 07:58:30 -05:00 committed by GitHub
parent f462457f92
commit 60f34e3015
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
from typing import Any
import jsonschema # type: ignore
from flask import current_app
from SpiffWorkflow.bpmn.serializer.helpers.registry import BpmnConverter # type: ignore
from SpiffWorkflow.bpmn.specs.data_spec import BpmnDataStoreSpecification # type: ignore
@ -85,7 +86,13 @@ class JSONDataStore(BpmnDataStoreSpecification, DataStoreCRUD): # type: ignore
data = my_task.data[self.bpmn_id]
# TODO: validate data against schema
try:
jsonschema.validate(instance=data, schema=model.schema)
except jsonschema.exceptions.ValidationError as e:
raise DataStoreWriteError(
f"Attempting to write data that does not match the provided schema for '{self.bpmn_id}': {e}"
) from e
model.data = data
db.session.add(model)