Skip to content

Commit 090c760

Browse files
committed
constraints type check
1 parent 52e6289 commit 090c760

File tree

1 file changed

+21
-10
lines changed
  • src/neo4j_graphrag/experimental/components

1 file changed

+21
-10
lines changed

src/neo4j_graphrag/experimental/components/schema.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ def validate_constraints_against_node_types(self) -> Self:
261261
if not self.constraints:
262262
return self
263263
for constraint in self.constraints:
264+
# Only validate UNIQUENESS constraints (other types will be added)
265+
if constraint.type != "UNIQUENESS":
266+
continue
267+
264268
if not constraint.property_name:
265269
raise SchemaValidationError(
266270
f"Constraint has no property name: {constraint}. Property name is required."
@@ -269,16 +273,15 @@ def validate_constraints_against_node_types(self) -> Self:
269273
raise SchemaValidationError(
270274
f"Constraint references undefined node type: {constraint.node_type}"
271275
)
272-
# Check if property_name exists on the node type (only if additional_properties is False)
276+
# Check if property_name exists on the node type
273277
node_type = self._node_type_index[constraint.node_type]
274-
if not node_type.additional_properties:
275-
valid_property_names = {p.name for p in node_type.properties}
276-
if constraint.property_name not in valid_property_names:
277-
raise SchemaValidationError(
278-
f"Constraint references undefined property '{constraint.property_name}' "
279-
f"on node type '{constraint.node_type}'. "
280-
f"Valid properties: {valid_property_names}"
281-
)
278+
valid_property_names = {p.name for p in node_type.properties}
279+
if constraint.property_name not in valid_property_names:
280+
raise SchemaValidationError(
281+
f"Constraint references undefined property '{constraint.property_name}' "
282+
f"on node type '{constraint.node_type}'. "
283+
f"Valid properties: {valid_property_names}"
284+
)
282285
return self
283286

284287
def node_type_from_label(self, label: str) -> Optional[NodeType]:
@@ -604,7 +607,7 @@ def _filter_relationships_without_labels(
604607
def _filter_invalid_constraints(
605608
self, constraints: List[Dict[str, Any]], node_types: List[Dict[str, Any]]
606609
) -> List[Dict[str, Any]]:
607-
"""Filter out constraints that reference undefined node types, have no property name,
610+
"""Filter out constraints that reference undefined node types, have no property name, are not UNIQUENESS type
608611
or reference a property that doesn't exist on the node type."""
609612
if not constraints:
610613
return []
@@ -629,6 +632,14 @@ def _filter_invalid_constraints(
629632

630633
filtered_constraints = []
631634
for constraint in constraints:
635+
# Only process UNIQUENESS constraints (other types will be added)
636+
if constraint.get("type") != "UNIQUENESS":
637+
logging.info(
638+
f"Filtering out constraint: {constraint}. "
639+
f"Only UNIQUENESS constraints are supported."
640+
)
641+
continue
642+
632643
# check if the property_name is provided
633644
if not constraint.get("property_name"):
634645
logging.info(

0 commit comments

Comments
 (0)