typedb icon indicating copy to clipboard operation
typedb copied to clipboard

Incorrect validation for negated attribute values in rules (invalidates valid rules)

Open thomaschristopherking opened this issue 2 years ago • 1 comments

Description

The following rule is invalidated because of a cyclical negation, but the negation is on a different attribute value in the antecedent to the one inferred by the consequent.

rule if-data-source-not-trusted-then-untrusted:
    when {
        $ds isa data_source;
        not { $ds has is_trusted true;};
    }
    then {
        $ds has is_trusted false;
    };

Environment

  1. Windows or Ubuntu
  2. TypeDB 2.8.0

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Load the following schema:
define

is_trusted sub attribute, value boolean;
data_source sub entity, owns is_trusted;

rule if-data-source-not-trusted-then-untrusted:
    when {
        $ds isa data_source;
        not { $ds has is_trusted true;};
    }
    then {
        $ds has is_trusted false;
    };

Expected Output

A successful schema commit

Actual Output

Validation error:

Invalid Rule Write: A cycle containing negation(s) that can cause inference contradictions has been detected in rules:
if-data-source-not-trusted-then-untrusted ->
if-data-source-not-trusted-then-untrusted

Additional information

If the rule contains a more general not { $ds has is_trusted $it;}; in the antecedent, then validation should still fail.

thomaschristopherking avatar Apr 13 '22 09:04 thomaschristopherking

Moved case with relations to different issue , because it's a different fix #6599

krishnangovindraj avatar Jun 17 '22 15:06 krishnangovindraj

PR #6628 adds support for this. It's currently in our development branch so should be included in the next release.

krishnangovindraj avatar Aug 25 '22 14:08 krishnangovindraj