FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: Derived where() on non-selected columns derived wrong results by jsam · Pull Request #107 · inputlayer/inputlayer · GitHub

fix: Derived where() on non-selected columns derived wrong results - #107

Merged
jsam merged 1 commit into
mainfrom
py/fix-rule-where-binding
Aug 20, 2026
Merged

fix: Derived where() on non-selected columns derived wrong results#107
jsam merged 1 commit into
mainfrom
py/fix-rule-where-binding

Conversation

jsam commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

What

compile_rule built body atoms before compiling the where-condition. A column referenced only by the condition compiled to _ in its atom while the condition referenced an unbound variable:

+gold_customer(Name) <- customer(_, Name, _), Tier = "gold"

The engine accepts that rule and silently satisfies the comparison, so the derived relation matched EVERY customer, silver included. Verified live before the fix; after the fix the clause binds the column and the engine filters correctly:

+gold_customer(Name) <- customer(_, Name, Tier), Tier = "gold"

The fix is an ordering change: conditions compile first, registering their columns in the variable environment before atoms are built. This is the shared compiler, so it affects every Derived rule with a where() on a non-selected column - define_rules and migrations alike.

How it slipped through

test_with_condition asserted the head and the condition string but never that the condition column was bound in the atom. It now does, plus a regression test asserting the exact clause for the condition-only-column case. Full SDK suite: 958 passed.

Found while building a live demo of the migration strategy. The engine-side half (accepting rules with unbound comparison variables and silently satisfying them - a wrong-results landmine of the same family as #91) is filed separately.

Merge order

Independent - no conflicts with #98-#105.

compile_rule built body atoms before compiling the where-condition, so
a column referenced only by the condition (not selected into the head)
compiled to _ in its atom while the condition referenced an unbound
variable: +gold(Name) <- customer(_, Name, _), Tier = "gold". The
engine accepts that rule and silently satisfies the comparison, so the
derived relation matched every row instead of filtering.

Conditions now compile first, registering their columns in the variable
environment before atoms are built:
+gold(Name) <- customer(_, Name, Tier), Tier = "gold".

Found by a live migration demo (a Derived with where(tier == "gold")
returned silver customers). The existing test_with_condition passed
because it never asserted the binding; it now does, plus a regression
test for the condition-only column case. Engine-side acceptance of
unbound comparison variables is filed separately.
jsam merged commit b756c77 into main Aug 20, 2026
11 checks passed
jsam deleted the py/fix-rule-where-binding branch August 20, 2026 11:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL