Repository navigation
Description
My workflow for reconciling hledger journal with my bank accounts is to add a transaction for today with balance assignments reflecting the current balance of the accounts. Then, I add missed transactions from the past until hledger print -x -ptoday shows all the balance assignment postings to be 0. After upgrading to 1.43, hlegder add prevents me from adding those older transactions unless I use the -I option. It seems that the change "whenever you enter an amount, [hledger add] now checks the journal's balance assertions" incorrectly affects balance assignments as well. Not the first time it turns out I seem to be the only person using balance assignments in hledger 😂
Example
My journal file:
2025-06-01 Transaction 1
account 100$
equity -100$
2025-06-10 Assert balance
account ==* 200$
equity:reconciliation
Failing add, note the date older than the balance assignment:
$ hledger add -f journal.hledger
Date [2025-06-10]: 6-8
Description: Missed transaction
Using this similar transaction for defaults:
2025-06-01 Transaction 1
account 100$
equity -100$
Account 1 [account]:
Amount 1 [100$]: 100$
/home/wojciech/hledger-repro/journal.hledger:6:15:
| 2025-06-10 Assert balance
6 | account 100$ ==* 200$
| ^^^^^^^^
| equity:reconciliation -100$
Balance assertion failed in account
Across all commodities at this point, including subaccounts, ignoring costs,
the asserted balance is: 200$
but the calculated balance is: 300$
(difference: -100$)
To troubleshoot, check this account's running balance with assertions disabled, eg:
hledger reg -I 'account'
Note as well that this fails even though I'm adding exactly $100, which is the amount missing in the assignment on 2025-06-10. I believe hledger add should succeed in this case regardless of the amount in the added posting.
Version
Running in wsl
$ hledger --version
hledger 1.43.1, linux-x86_64
Activity
[-]Balance assignments prevent adding older transactions[/-][+]Balance assignments prevent adding older transactions in 1.43[/+]simonmichael commentedon Jun 11, 2025
Because of the downsides.. :-)
But thank you for reporting this, and sorry for breaking your workflow. We did discuss balance assignments as part of #2356, but it looks like we didn't quite finish testing or documenting them in this context. @reesmichael1 I seem to remember a docs update, but I don't see assertions/assignments mentioned at https://hledger.org/dev/hledger.html#add ?
simonmichael commentedon Jun 11, 2025
To be clear, are you able to work as before by adding
-I?simonmichael commentedon Jun 11, 2025
Also just curious, is there any advantage to using a balance assignment here instead of an assertion like
? It makes the journal usable even when you have not yet caught up with data entry ?
simonmichael commentedon Jun 11, 2025
And I suppose this is actually a regression. So claim your https://hledger.org/REGRESSIONS.html#regression-finder-bounty within 7 days!
wgslr commentedon Jun 11, 2025
Thanks for a very quick response!
Yes, seems so, although I was lazy about it and quickly reverted to 1.42.
Do you mean that I could then use the assertion error to know when I'm fully caught up?
I'd list the following benefits:
-IIn this journal,
hledger print -ximmediately tells me I'm missing $100 in checking and $2000 in savings:With an assertion, I would only see the $100 difference in
checkingat first and not know ifsavingsbalance is correct:I do agree I should probably add an explicit
0 ==* $200after I'm done with reconciliation, to make the journal more explicit and avoid quietly introducing errors later. But the current workflow seems awfully convenient during the data entry.Oh, nice, thank you!
simonmichael commentedon Jun 11, 2025
That makes sense. Interesting workflow, thanks.
[-]Balance assignments prevent adding older transactions in 1.43[/-][+]1.43: adding transactions before a balance assignment no longer works[/+][-]1.43: adding transactions before a balance assignment no longer works[/-][+]1.43: adding transactions before a balance assignment no longer works, requires -I[/+][-]1.43: adding transactions before a balance assignment no longer works, requires -I[/-][+]1.43-1.43.1: adding transactions before a balance assignment no longer works, requires -I[/+]simonmichael commentedon Jun 13, 2025
@reesmichael1 I believe this is a limitation / some fallout from #2356. In confirmedTransactionWizard we balance the transaction and check its balance assertion (if any) in the context of the journal:
But the journal has had all missing amounts filled in by the time the add command runs; there are no balance assignments in it any more, just explicit amounts.
It seems we'll need to keep the journal's missing amounts missing, and after each amount is entered, add the new posting to the journal, wrapped in a possibly incomplete transaction, so we can call journalBalanceTransactions to recalculate balance assignments and check assertions.
simonmichael commentedon Jun 13, 2025
Two ways to preserve the original journal amounts:
add.addneeds to check assignments/assertions, restore the journal's original posting (amounts), which are stored in Posting's poriginal field. (Effectively undoing part of what journalFinalise did.);fix:doc:add: document balance assertions/assignments behaviour [#2406]
;doc: add: balance assignments: mention -I [#2406]
simonmichael commentedon Jun 13, 2025
Now documented. It would be cool to make this work in the expected way without needing -I, but I probably won't have time for it myself.
;fix:doc:add: document balance assertions/assignments behaviour [#2406]
;doc: add: balance assignments: mention -I [#2406]
;fix:doc:add: document balance assertions/assignments behaviour [#2406]
;doc: add: balance assignments: mention -I [#2406]
reesmichael1 commentedon Jun 16, 2025
Yikes. Thanks for taking care of this @simonmichael! Sorry for my delay, I was on vacation for the last week.
;fix:doc:add: document balance assertions/assignments behaviour [hled…
;doc: add: balance assignments: mention -I [hledgerorg#2406]