possible bug in transaction involving three commodities

34 views
Skip to first unread message

Rik Snel

unread,
May 27, 2023, 12:26:26 PM5/27/23
to hledger
Hi all,

(I sent this mail yesterday and this morning, but somehow it didn't get though; so I'm now trying to send it through the web interface)

I'm migrating from ledger to hledger, because I really like the balance
assertions that include subaccounts. My ledgerfile, which contains more that 10
years of data, turned out to be full of errors that hledger didn't like
(misordered transactions that messed up balance assertions, also balance
assignments to '0' where hledger seems to require a commodity to be specified
to work as expected). While I was sorting this all out, I think I may have
stumbled on a bug regarding a three commodity trade where the prices are
specified with @@.

Here is a minimal example, note that the last posting only has a
balance assertion:

-----------------------------------------------------
2023/01/02 * Trade
        Assets                  AAA-1.1 @@ CCC 2
        Assets                  BBB-1.2 @@ CCC 3
        Expenses:Fees           CCC 0.1
        Assets                  = CCC 4.9
-----------------------------------------------------

hledger says:

-----------------------------------------------------
hledger: Error: /home/user/journal:1-5:
1 | 2023-01-02 * Trade
  |     Assets                AAA-1.1
  |     Assets                BBB-1.2
  |     Expenses:Fees         CCC 0.1
  |     Assets                CCC 4.9 = CCC 4.9

Consider adjusting this entry's amounts, adding missing postings,
or recording conversion price(s) with @, @@ or equity postings.
----------------------------------------------------

Notice that it acts like the '@@'s are not there. When I add "CCC 4.9"
before the balance assertion, then hledger accepts the transaction.

-----------------------------------------------------
2023/01/02 * Trade
        Assets                  AAA-1.1 @@ CCC 2
        Assets                  BBB-1.2 @@ CCC 3
        Expenses:Fees           CCC 0.1
        Assets                  CCC 4.9 = CCC 4.9
------------------------------------------------------

What do you think?

Greetings,

Rik.

Simon Michael

unread,
May 27, 2023, 1:29:01 PM5/27/23
to hledger
On May 27, 2023, at 05:24, 'Rik Snel' via hledger <hle...@googlegroups.com> wrote:
I'm migrating from ledger to hledger, because I really like the balance
assertions that include subaccounts. My ledgerfile, which contains more that 10
years of data, turned out to be full of errors that hledger didn't like
(misordered transactions that messed up balance assertions, also balance
assignments to '0' where hledger seems to require a commodity to be specified
to work as expected).


Welcome Rik,

that's a great test of https://hledger.org/ledger.html#differences ...

https://hledger.org/ledger.html#balance-assertions--assignments does not mention the assignment to zero issue - would you mind showing an example of how Ledger does it differently ?


While I was sorting this all out, I think I may have
stumbled on a bug regarding a three commodity trade where the prices are
specified with @@.

Here is a minimal example, note that the last posting only has a
balance assertion:

-----------------------------------------------------
2023/01/02 * Trade
        Assets                  AAA-1.1 @@ CCC 2
        Assets                  BBB-1.2 @@ CCC 3
        Expenses:Fees           CCC 0.1
        Assets                  = CCC 4.9
-----------------------------------------------------

hledger says:

-----------------------------------------------------
hledger: Error: /home/user/journal:1-5:
1 | 2023-01-02 * Trade
  |     Assets                AAA-1.1
  |     Assets                BBB-1.2
  |     Expenses:Fees         CCC 0.1
  |     Assets                CCC 4.9 = CCC 4.9

Consider adjusting this entry's amounts, adding missing postings,
or recording conversion price(s) with @, @@ or equity postings.
----------------------------------------------------


That's an interesting example. The implicit last amount is constrained in two ways:

1. by the balance assignment (it must be the amount that brings Assets's CCC balance to 4.9) 

2. and by transaction balancing (it must be the amount that brings AAA -1.1 @@ CCC 2 + BBB -1.2 @@ CCC 3 + CCC 0.1 to 0).

Ledger interprets the transaction this way:

$ ledger -f a.j print
2023/01/02 * Trade
    Assets                                   AAA-1.1 @@ CCC 2.0
    Assets                                   BBB-1.2 @@ CCC 3.0
    Expenses:Fees                            CCC 0.1
    Assets                                   CCC 4.9 = CCC 4.9

and as you say, hledger accepts this interpretation - if it's given with all amounts explicit.

Is transaction balancing supposed to balance *costs*, ie convert all amounts to cost before balancing ? I never quite thought of it that way, and it isn't spelled out at https://hledger.org/dev/hledger.html#costs or in Ledger docs, but yes, I think that is the customary behaviour.

So the interpretation above is correct, and yes, this does seem like a hledger bug. Also, the actual error message includes this info which seems like it should mention the costs, instead:

The real postings' sum should be 0 but is: AAA-1.1, BBB-1.2, CCC 5.0

Simon Michael

unread,
May 27, 2023, 2:46:56 PM5/27/23
to hledger
I opened https://github.com/simonmichael/hledger/issues/2039 for this and have pushed a fix. Thanks for the report !

Rik Snel

unread,
May 30, 2023, 12:51:37 PM5/30/23
to hledger
The error message of hledger starts with:

This multi-commodity transaction is unbalanced.

The real postings' sum should be 0 but is: AAA-1.1, BBB-1.2, CCC 5.0

This information did not end up in my original post...

Rik Snel

unread,
May 30, 2023, 12:51:37 PM5/30/23
to hledger
Hi Simon,

Thanks for your quick and friendly response. I will create an issue on github for this bug.

An example of the difference between ledger and hledger with " = 0 "
-----
2023/01/01 * Opening Balances
        Assets:ToZero           EUR 2
        Equity:Opening Balances

2023/01/02 * Testcase
        Assets:Fromzero         EUR 2
        Assets:ToZero           = 0
-----

hledger gives an error:
hledger: Error: /home/rsnel/test.dat:5-7:
5 | 2023-01-02 * Testcase
  |     Assets:Fromzero           EUR 2
  |     Assets:ToZero                 0 = 0

This transaction is unbalanced.
The real postings' sum should be 0 but is: EUR 2
Consider adjusting this entry's amounts, or adding missing postings.

which can be fixed by saying "= EUR 0" instead of "= 0".

ledger deducts EUR 2 from Assets:ToZero when "= 0" is specified and
also when "= EUR 0" is specified.

One other thing: I discovered that ledger 3.2.1-20200518 (that's the version that I use)
does not check balance assertions that look like this:
-----
2023/01/01 * AssertFail
        Assets:To               EUR 5
        Assets:From             = EUR 0
----
hledger complains rightly, but my version of ledger says nothing, so there were a couple
of wrong assertions in my ledger file that hledger noticed, but ledger not.

Greetings,

Rik.

Simon Michael

unread,
May 30, 2023, 1:06:58 PM5/30/23
to hledger
RIk - something was amiss with mail list approval, sorry for the delay. I think these two old messages of yours delivered today are obsolete, if not let me know.



-- 
You received this message because you are subscribed to the Google Groups "hledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hledger+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hledger/bbadb6a4-be20-4188-95e8-64a952f92d0an%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages