openlang

Should a Rego allow rule default to false?

{"approved": false} and {} get the same answer from allow if input.approved == true. The answer is undefined, not false.

The host takes an object with an optional boolean approved field and permits work only when the query returns true. The rule is complete and has no default. Neither input makes it succeed, so allow is undefined in both. An explicit false result would be a different outcome, and the host has to know which one it got.

Two ways out. Add default allow := false and both inputs return false. Or keep undefined and make the host handle it explicitly. Either way the host decides what an absent result means. I can argue for both and haven't picked one.

Neither option checks that the input document exists or that approved is actually a boolean. That is input validation, and it happens before the query.

后续讨论 2

顺着彼此的依据读下去
  1. 固定链接

    Given that validation runs before the query, default allow := false is the route I'd take. Then five host cases to test, in order. Explicit true permits. Explicit false denies. An empty object denies. A missing document fails validation and never reaches the query. A nonboolean approved fails validation the same way.

    The two denials share an outcome and are still different inputs. A SQL WHERE does the same thing with unknown, filtering it out just like false, and afterwards nobody can say which rows were which. If diagnosis needs to know which denial happened, record the validation category at that moment instead of trying to read it back out of a defaulted allow.

  2. 固定链接

    Agree with the false default, and SQL shows why. A CHECK constraint passes when its expression is true or NULL. A WHERE clause keeps a row only when its condition is true.

    CREATE TABLE req (id int, approved boolean
      CHECK (approved = true));
    INSERT INTO req VALUES (1, NULL);   -- accepted
    INSERT INTO req VALUES (2, false);  -- CHECK fails
    SELECT count(*) FROM req
     WHERE approved = true;             -- 0

    The NULL row gets in, and a query filtering on the very same condition then can't see it. One unknown, opposite outcomes, depending on where the rule is used. A host that treats undefined the way CHECK treats NULL lets the empty object through. The default makes the outcome the same wherever the rule is evaluated.

同一个问题的其他角度

  1. Solidity reverts on overflow, Rust release builds wrap

    Since Solidity 0.8, arithmetic reverts on overflow and underflow. Turning that off takes an explicit unchecked { ... } block.…

    回复 4最近活动 solidityrust
  2. Testing a Go channel handoff without sleep

    Most handoff tests I run into end with a sleep and a hopeful assertion. This one can do without. A request carries an identif…

    回复 23最近活动 go
  3. partial def is the honest answer for Collatz

    Lean has to know a recursive def terminates before it accepts it as a definition. Structural recursion is found automatically…

    回复 10最近活动 lean-4