Repository navigation
Description
A posting whose units number is written but whose currency is omitted (IncompleteAmount::NumberOnly) is silently dropped or silently rewritten, and the transaction is accepted however unbalanced it is. rledger check reports success.
Found while self-reviewing #1919. Pre-existing on main (45cc9b961), not introduced by that PR.
The worst case: the amount is replaced
2010-01-01 open Assets:A
2010-01-01 open Assets:B
2010-05-28 * "currency omitted by typo"
Assets:A 120.00
Assets:B -999.00 USD
$ rledger check n3.beancount
✓ No errors found
$ rledger query n3.beancount "SELECT account, units"
Assets:A 999.00 USD <- the author wrote 120.00
Assets:B -999.00 USD
The number the author typed is discarded and replaced with whatever balances the transaction. A dropped currency is an easy typo, and this turns it into a silently fabricated amount.
The other two shapes: the posting is dropped
2010-05-28 * "NumberOnly with a price"
Assets:A 120.00 @ 1.2 USD
Assets:B -999.00 USD
✓ No errors found
Assets:A (no units) price=1.20 USD
Assets:B -999.00 USD
Same with a cost (Assets:A 10 {300.00 USD} against -999.00 USD): units dropped, no error. In both, SELECT sum(weight) is non-zero and check still passes.
Mechanism
interpolate's NumberOnly arm resolves a currency from the cost or price and adds the raw number to that currency's residual, but never registers the posting as something that must be filled:
Some(IncompleteAmount::NumberOnly(number)) => {
if let Some(curr) = number_only_currency(posting) {
*residuals.entry(curr.clone()).or_default() += *number;
} else {
unassigned_missing.push(i);
}
}Two consequences:
-
With a cost or price in reach, the posting stays
NumberOnlyforever. Nothing fills it and nothing errors, sovalidate_transaction_balancehits its documented early return (if txn.postings.iter().any(|p| p.amount().is_none())) and skips the balance check entirely. That early return is only sound when interpolation has already reported a failure, which is exactly the invariant established in cannot interpolate a missing units number when a cost is present #1911. -
Without one, the posting joins
unassigned_missingand is filled from the residual as if it were fully elided, overwriting the number that was there (the 120.00 to 999.00 case).
Adding the price multiplier is also wrong on its own: 120.00 @ 1.2 USD weighs 144.00 USD, but the residual receives 120.00.
Python beancount
Rejects all three, and is right to: the units currency is genuinely unknowable.
| input | beancount |
|---|---|
120.00 @ 1.2 USD |
CategorizationError |
10 {300.00 USD} |
CategorizationError |
120.00 |
ValidationError (does not balance) |
Note tests/fixtures/lima-tests/IncompleteInputs.UnitsMissingCurrency*.beancount cover this family and currently pass only because E1001 masks them (no open directives); under auto_accounts they expose the behaviour.
Suggested shape
A NumberOnly posting has an unknown units currency, so it is an unknown for the one-per-group rule rather than a known contribution. Either fill the currency and keep the author's number, or refuse. What it must not do is keep the number and drop the currency, or keep the currency and replace the number.
Severity: silent acceptance of an unbalanced transaction plus a fabricated amount, from a one-character typo.
Activity
fix(booking): keep the number when only the currency is elided
fix(booking): keep the number when only the currency is elided
fix(booking): keep the number when only the currency is elided