Repository navigation
fix(query): only() propagates NULL in its first argument - #1702
Merged
Merged
Conversation
first(cost_currency) is NULL for groups without costs; beanquery propagates NULL through only(), rustledger raised a type error — which 500'd fava's Holdings by_currency page for any ledger with a costless commodity group (the standard example ledger included). The second-argument match already propagated NULL; the asymmetry was the bug. Regression test drives the exact Holdings expression shape. Closes #1699 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes BQL only() to propagate NULL when its first argument evaluates to NULL, matching beanquery behavior and preventing Holdings-by-currency queries (e.g., fava) from failing on costless groups.
Changes:
- Update
ONLYfunction evaluation to returnNULLwhen the first argument isValue::Null(instead of raising a type error). - Add an integration regression test that reproduces the Holdings-style expression shape where
first(cost_currency)isNULL.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/rustledger-query/src/executor/mod.rs | Fix ONLY first-argument handling to propagate NULL for beanquery parity. |
| crates/rustledger-query/tests/bql_integration_test.rs | Add regression test ensuring only(NULL, inventory) returns NULL (no type error). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-07-02)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Merged
robcohen
added a commit
that referenced
this pull request
Jul 3, 2026
Minor (breaking) release carrying the route-smoke fix wave (#1699/#1700/ #1701, found by rustfava's new route-smoke suite): - BREAKING parser/booking: compound cost {a # b} now carries both components and weighs N*a + b per beancount (#1700, via #1704). Ledgers that balanced under the old {a # b} == {{b}} misreading were genuinely unbalanced and now error; lot cost bases for compound specs are now correct. Binary caches invalidate automatically (CACHE_VERSION 13). - BREAKING plugin-types: CostNumberData gained the Compound variant — exhaustive matches in plugin code need a new arm (deliberate: silent mishandling of compound costs is the failure mode the exhaustive enum prevents). - FFI: WIT rustledger:ledger 3.2.0 -> 3.3.0 (additive compound case); runtime API_VERSION 3.3. Embedders regenerate bindings (rustfava#234); post-booking egress is unaffected. - query: only() propagates NULL (fava Holdings by_currency 500, #1699 via #1702); one-arg value() is inventory-typed for every row and the component declares column datatypes from the first non-NULL value (#1701, via #1703). Workspace 0.19.1 -> 0.20.0; packages/mcp-server bumped to match. Co-authored-by: Claude Opus 4.8 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Jul 3, 2026
Closes #1699 (the remaining half — only() was fixed in #1702). Scalar functions applied to NULL raised a type error instead of propagating, so expressions like abs(sum(number(value(position)))) — which rustfava's Holdings report runs on every render — failed compilation whenever the inner aggregate yielded NULL for a group. NULL now propagates through: YEAR, MONTH, DAY, QUARTER, UPPER, LOWER, TRIM, ABS, LENGTH, NEG, ACCOUNT_SORTKEY, PARENT, LEAF, ROOT, ROUND, and the second argument of FILTER_CURRENCY and POSSIGN. EMPTY keeps its deliberate NULL -> true semantic (a missing inventory is empty). STR/ INT/DECIMAL/BOOL casts, NUMBER, CURRENCY, UNITS, COST, CONVERT, SAFEDIV and COALESCE already handled NULL. New integration test locks the whole scalar surface, including the rustfava Holdings shape and second-argument propagation.
robcohen
added a commit
that referenced
this pull request
Jul 4, 2026
…1711) * fix(query): typed scalar functions propagate NULL (beanquery parity) Closes #1699 (the remaining half — only() was fixed in #1702). Scalar functions applied to NULL raised a type error instead of propagating, so expressions like abs(sum(number(value(position)))) — which rustfava's Holdings report runs on every render — failed compilation whenever the inner aggregate yielded NULL for a group. NULL now propagates through: YEAR, MONTH, DAY, QUARTER, UPPER, LOWER, TRIM, ABS, LENGTH, NEG, ACCOUNT_SORTKEY, PARENT, LEAF, ROOT, ROUND, and the second argument of FILTER_CURRENCY and POSSIGN. EMPTY keeps its deliberate NULL -> true semantic (a missing inventory is empty). STR/ INT/DECIMAL/BOOL casts, NUMBER, CURRENCY, UNITS, COST, CONVERT, SAFEDIV and COALESCE already handled NULL. New integration test locks the whole scalar surface, including the rustfava Holdings shape and second-argument propagation. * fix(booking): merge_with_padding is idempotent on already-merged input Closes #1712. query-entries runs merge_with_padding on host-provided entries; embedders (rustfava) pass load-full output, which is already merged. Debug builds aborted on the guard (wasm trap poisoning the component instance — how the downstream job failed on this PR); release builds re-applied pads against an inventory already containing the synths. Input with synth pad transactions is now returned unchanged; the should-panic guard test became an idempotence test. * fix(query): arithmetic operators propagate NULL The next layer behind the scalar fix (found by the downstream job's second pass): the Holdings expression tail is safediv(...) * 100, and with abs(NULL) fixed the query reached 'NULL * 100' and failed with 'arithmetic requires numeric values'. NULL operands now yield NULL (SQL/beanquery semantics), locked by tests. * docs(test): backtick abs() in doc comment (clippy doc-markdown) * test(query): NULL-literal cases, round() coverage, doc fix (review) - Date/numeric NULL propagation now asserted via the NULL literal directly (clearer intent, decoupled from column behavior); the string block keeps payee to exercise the real column pipeline. - round(NULL) was in the propagation list but untested — added. - empty(NULL) asserted via the literal. - Doc: payee is a transaction-level field the posting rows inherit. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the first of the three route-smoke findings:
only(NULL, inv)now returns NULL (beanquery parity) instead oftype error: ONLY: first argument must be a currency string.Root cause (from the #1699 analysis): the first-arg match sent everything non-String — including
Value::Nullfromfirst(cost_currency)on costless groups — to the error branch. The second-arg match already propagated; the asymmetry was the bug. User impact fixed: fava's Holdings → by currency page 500'd on ordinary ledgers.Regression test drives the exact Holdings expression shape (
only(first(cost_currency), cost(sum(position)))over a costless group → NULL row, not an error).The broader NULL-propagation sweep across typed scalar functions (also suggested in #1699) is left as a follow-up — this PR is the minimal user-facing fix.
Closes #1699
🤖 Generated with Claude Code