make sure no one deletes elements that were matched in the RHS with a RHS-condition...
This commit is contained in:
parent
6314506ac0
commit
7914f01006
1 changed files with 11 additions and 1 deletions
|
|
@ -82,8 +82,18 @@ def rewrite(state,
|
||||||
# to be grown
|
# to be grown
|
||||||
rhs_match = { name : lhs_match[name] for name in common }
|
rhs_match = { name : lhs_match[name] for name in common }
|
||||||
|
|
||||||
|
|
||||||
|
bound_api = bind_api(host_odapi)
|
||||||
|
original_delete = bound_api["delete"]
|
||||||
|
def wrapped_delete(obj):
|
||||||
|
not_allowed_to_delete = { host_odapi.get(host_name): pattern_name for pattern_name, host_name in rhs_match.items() }
|
||||||
|
if obj in not_allowed_to_delete:
|
||||||
|
pattern_name = not_allowed_to_delete[obj]
|
||||||
|
raise Exception(f"\n\nYou're trying to delete the element that was matched with the RHS-element '{pattern_name}'. This is not allowed! You're allowed to delete anything BUT NOT elements matched with your RHS-pattern. Instead, simply remove the element '{pattern_name}' from your RHS, if you want to delete it.")
|
||||||
|
return original_delete(obj)
|
||||||
|
bound_api["delete"] = wrapped_delete
|
||||||
builtin = {
|
builtin = {
|
||||||
**bind_api(host_odapi),
|
**bound_api,
|
||||||
'matched': matched_callback,
|
'matched': matched_callback,
|
||||||
'odapi': host_odapi,
|
'odapi': host_odapi,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue