mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-27 10:15:10 +00:00
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:
parent
f462457f92
commit
60f34e3015
@ -1,5 +1,6 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
import jsonschema # type: ignore
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from SpiffWorkflow.bpmn.serializer.helpers.registry import BpmnConverter # type: ignore
|
from SpiffWorkflow.bpmn.serializer.helpers.registry import BpmnConverter # type: ignore
|
||||||
from SpiffWorkflow.bpmn.specs.data_spec import BpmnDataStoreSpecification # 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]
|
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
|
model.data = data
|
||||||
|
|
||||||
db.session.add(model)
|
db.session.add(model)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user