Skip to content

Commit 93a3dbf

Browse files
chiattjacobtylerwalls
authored andcommitted
Validates node config on graph save, #10552
1 parent b82a41d commit 93a3dbf

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

arches/app/datatypes/base.py

+6
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,9 @@ def pre_structure_tile_data(self, tile, nodeid, **kwargs):
462462
Adds properties to a tile necessary for some clients, but not essential to the tile
463463
"""
464464
pass
465+
466+
def validate_node(self, node):
467+
"""
468+
Confirms that a node is properly configured to collect data
469+
"""
470+
return {"success": True}

arches/app/datatypes/datatypes.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -2691,4 +2691,23 @@ def default_es_mapping(self):
26912691
},
26922692
}
26932693
}
2694-
return mapping
2694+
return mapping
2695+
2696+
def validate_node(self, node):
2697+
valid = False
2698+
message = ""
2699+
title = ""
2700+
try:
2701+
uuid.UUID(node.config["controlledList"])
2702+
valid = True
2703+
except TypeError:
2704+
message = _("A reference datatype node must be configured with a controlled list")
2705+
title = _("Invalid Node Configuration")
2706+
logger.error(message)
2707+
2708+
except Exception as e:
2709+
message = _("Ensure your node is propertly configured for the reference datatype")
2710+
title = _("Invalid Node Configuration")
2711+
logger.error(message)
2712+
2713+
return {"success": valid, "message": message, "title": title}

arches/app/models/graph.py

+10
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,13 @@ def _validate_node_name(self, node):
16751675
message = _('Duplicate node name: "{0}". All sibling node names must be unique.'.format(node.name))
16761676
raise GraphValidationError(message)
16771677

1678+
def _validate_node_config(self, node, datatype_factory):
1679+
datatype = datatype_factory.get_instance(node.datatype)
1680+
validation = datatype.validate_node(node)
1681+
if validation["success"] is False:
1682+
message = validation["message"]
1683+
raise GraphValidationError(message)
1684+
16781685
def create_node_alias(self, node):
16791686
"""
16801687
Assigns a unique, slugified version of a node's name as that node's alias.
@@ -1739,8 +1746,11 @@ def validate_fieldname(fieldname, fieldnames):
17391746
return fieldname
17401747

17411748
fieldnames = {}
1749+
datatype_factory = DataTypeFactory()
1750+
17421751
for node_id, node in self.nodes.items():
17431752
self._validate_node_name(node)
1753+
self._validate_node_config(node, datatype_factory)
17441754
if node.exportable is True:
17451755
if node.fieldname is not None:
17461756
validated_fieldname = validate_fieldname(node.fieldname, fieldnames)

0 commit comments

Comments
 (0)