You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
1.22: Regression error of inferred prices with @@ directive #1736
I updated hledger from 1.21 to 1.22.2 and found that I couldn't print my balancesheet anymore due to an error "hledger: Ratio has zero denominator". After bisect, the minimal example uses two balance assertions, one using a total price (@@) directive.
Failing example with hledger > 1.21 (also tried with latest release hledger 47b5b6b, linux-x86_64):
;; Total asset value should be 400 USD + 1000 USD = 1400 USD
2021-10-15 Broker initial balance (equity ABC)
Assets:Broker = 4 ABC @@ 400 USD
Equity:Opening Balances
2021-10-15 Broker initial balance (USD)
Assets:Broker = 1000 USD
Equity:Opening Balances
$ hledger --version
hledger 1.22.2, linux-x86_64
$ hledger prices --costs
P 2021-10-15 ABC 100.0 USD
hledger: Ratio has zero denominator
I'm not 100% sure what is causing this issue, but your journal is not doing what you think it should. In the second transaction you are asking for a balance assignment, which means that the final value will not be 1400 USD, but rather 1000 USD. To get what you seem to want, use the following journal:
;; Total asset value should be 400 USD + 1000 USD = 1400 USD
2021-10-15 Broker initial balance (equity ABC)
Assets:Broker = 4 ABC @@ 400 USD
Equity:Opening Balances
2021-10-15 Broker initial balance (USD)
Assets:Broker 1000 USD
Equity:Opening Balances
changed the title [-]Regression error of inferred prices with @@ directive[/-][+]Regression error of inferred prices with @@ directive (since 1.22)[/+]on Nov 14, 2021
;; Total asset value should be 400 USD + 1000 USD = 1400 USD
2021-10-15 Broker initial balance (equity ABC)
Assets:Broker = 4 ABC @@ 400 USD
Equity:Opening Balances
2021-10-15 Broker initial balance (USD)
Assets:Broker = 1000 USD
Equity:Opening Balances
I'm only remarking on whether this journal is the correct journal, given the comment at the top. They seem to be expecting a final balance of 1400 USD in assets:Broker, whereas I believe this is asserting a final balance of 4 ABC, 1000 USD. I may be misinterpreting what they're expecting.
It then tries to infer the price by calculating 0 / 0, which is causing the divide by zero error here. I'll try to figure out where this is going wrong.
changed the title [-]Regression error of inferred prices with @@ directive (since 1.22)[/-][+]1.22: Regression error of inferred prices with @@ directive[/+]on Dec 16, 2023
Activity
Xitian9 commentedon Nov 14, 2021
I'm not 100% sure what is causing this issue, but your journal is not doing what you think it should. In the second transaction you are asking for a balance assignment, which means that the final value will not be 1400 USD, but rather 1000 USD. To get what you seem to want, use the following journal:
simonmichael commentedon Nov 14, 2021
Thanks for the report, and sorry I lost track of it. Confirmed, claim your https://hledger.org/regressionbounty when you like!
[-]Regression error of inferred prices with @@ directive[/-][+]Regression error of inferred prices with @@ directive (since 1.22)[/+]simonmichael commentedon Nov 14, 2021
I'm not seeing what you mean @Xitian9; the example looks like it should work, to me.
Testing some similar balance assertions:
Balance assertions are known to ignore transaction prices:
https://hledger.org/hledger.html#assertions-and-prices
Balance assignments are expected to use transaction prices:
https://hledger.org/hledger.html#balance-assignments-and-prices
simonmichael commentedon Nov 14, 2021
(The reported issue seems to be fallout from 5e7b693.)
Xitian9 commentedon Nov 15, 2021
I'm only remarking on whether this journal is the correct journal, given the comment at the top. They seem to be expecting a final balance of 1400 USD in
assets:Broker, whereas I believe this is asserting a final balance of4 ABC, 1000 USD. I may be misinterpreting what they're expecting.Xitian9 commentedon Nov 15, 2021
Aha. The problem seems to be that, with that second balance assertion, hledger is asserting the amount to be:
It then tries to infer the price by calculating
0 / 0, which is causing the divide by zero error here. I'll try to figure out where this is going wrong.Xitian9 commentedon Nov 15, 2021
This actually points to a more general issue: we now allow zero-prices within hledger. For example, each of the following are allowable.
These are valid, and it is impossible to calculate unit prices in at least one direction. How should we handle this?
simonmichael commentedon Nov 15, 2021
That problem arises with --infer-market-prices, right ? We could respect zero numerators and ignore zero denominators ? I think that would mean:
0 ABC @@ 10 USD- no price is inferred for ABC; 0 ABC price is inferred for USD10 ABC @@ 0 USD- 0 USD price is inferred for ABC; no price is inferred for USDOr, I'm fine with having --infer-market-prices just ignore it if there's a zero on either side.
Xitian9 commentedon Nov 15, 2021
Yes, that's also valid. Should it issue a warning, or just happily ignore?
simonmichael commentedon Nov 15, 2021
No warning, just ignore.
simonmichael commentedon Nov 15, 2021
If unnoticed zeroes ever turn out to be a significant problem, check would be the place to warn about them.
fix: prices: Do not include zero amounts when calculating amounts for…
fix: prices: Do not include zero amounts when calculating amounts for…
fix: prices: Do not include zero amounts when calculating amounts for…
simonmichael commentedon Nov 19, 2021
Thanks!
[-]Regression error of inferred prices with @@ directive (since 1.22)[/-][+]1.22: Regression error of inferred prices with @@ directive[/+]