Skip to content

Commit

Permalink
Add check for deletion policies in properties. (#7675)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnwpark authored Aug 23, 2024
1 parent d787c14 commit 9dbff5f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
24 changes: 18 additions & 6 deletions edb/schema/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,27 @@ def validate_object(
span=span,
)

def _check_linkprop_errors(self, node: qlast.DDLOperation) -> None:
def _check_field_errors(self, node: qlast.DDLOperation) -> None:
for sub in node.commands:
# do not allow link property on properties
if isinstance(sub, qlast.CreateConcretePointer):
raise errors.InvalidDefinitionError(
f'cannot create a link property on a property',
f'cannot place a link property on a property',
span=node.span,
hint='Link properties can only be created on links, whose '
'target types are object types.',
hint=(
'Link properties can only be placed on links, whose '
'target types are object types.'
),
)
# do not allow on source/target delete on properties
if isinstance(sub, (qlast.OnSourceDelete, qlast.OnTargetDelete)):
raise errors.InvalidDefinitionError(
f'cannot place a deletion policy on a property',
span=node.span,
hint=(
'Deletion policies can only be placed on links, whose '
'target types are object types.'
),
)


Expand All @@ -310,7 +322,7 @@ def _cmd_tree_from_ast(
if isinstance(astnode, qlast.CreateConcreteProperty):
assert isinstance(cmd, PropertyCommand)
cmd._process_create_or_alter_ast(schema, astnode, context)
cmd._check_linkprop_errors(astnode)
cmd._check_field_errors(astnode)

return cmd

Expand Down Expand Up @@ -433,7 +445,7 @@ def _cmd_tree_from_ast(
cmd._process_create_or_alter_ast(schema, astnode, context)
else:
cmd._process_alter_ast(schema, astnode, context)
cmd._check_linkprop_errors(astnode)
cmd._check_field_errors(astnode)
return cmd

def _apply_field_ast(
Expand Down
24 changes: 23 additions & 1 deletion tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def test_schema_bad_link_06(self):
"""

@tb.must_fail(errors.InvalidDefinitionError,
"cannot create a link property on a property")
"cannot place a link property on a property")
def test_schema_link_prop_on_prop_01(self):
"""
type Test1 {
Expand All @@ -432,6 +432,28 @@ def test_schema_link_prop_on_prop_01(self):
};
"""

@tb.must_fail(errors.InvalidDefinitionError,
"cannot place a deletion policy on a property")
def test_schema_deletion_policy_on_prop_01(self):
"""
type Test1 {
title : str {
on source delete allow;
}
};
"""

@tb.must_fail(errors.InvalidDefinitionError,
"cannot place a deletion policy on a property")
def test_schema_deletion_policy_on_prop_02(self):
"""
type Test1 {
title : str {
on target delete restrict;
}
};
"""

@tb.must_fail(errors.QueryError,
"could not resolve partial path")
def test_schema_partial_path_in_default_of_link_prop_01(self):
Expand Down

0 comments on commit 9dbff5f

Please sign in to comment.