GnuCash
Contact   Instructions
Bug 798015 - cash flow numerical-overflow
Summary: cash flow numerical-overflow
Status: RESOLVED FIXED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: Reports (show other bugs)
Version: 4.2
Hardware: PC Linux
: Normal normal
Target Milestone: ---
Assignee: reports
QA Contact: reports
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-20 10:36 EST by mr.lequoctuan
Modified: 2020-11-26 10:25 EST (History)
4 users (show)

See Also:


Attachments
cashflow exception (2.10 KB, text/plain)
2020-11-20 10:36 EST, mr.lequoctuan
no flags Details
file cause bug (6.02 KB, application/gzip)
2020-11-20 14:58 EST, mr.lequoctuan
no flags Details

Description mr.lequoctuan 2020-11-20 10:36:42 EST
Created attachment 373917 [details]
cashflow exception

Hi there,
When I open Reports -> Income & expense -> Cash flow, following exception was throw

...
In cash-flow-calc.scm:
    61:36  3 (_ #<swig-pointer Split * 5583dabb4ee0>)
In standard/cash-flow.scm:
   229:13  2 (to-report-currency _ _ 1369501200)
In commodity-utilities.scm:
   702:12  1 (gnc:exchange-by-pricedb-nearest _ #<swig-pointer gnc_commodity * 5583d8d984b0> _)
In unknown file:
           0 (gnc-pricedb-convert-balance-nearest-price-t64 #<swig-pointer struct gnc_price_db_s * 5583d8d61860> 50 #<swig-pointer gnc_commodity * 5583d8d973c0> #<swig-pointer gnc_commodity * 5583d8d984b0> 1369544400)

Throw to key `numerical-overflow' with args `("/" "Numerical overflow" #f #f)'.

If I create new file, that not happend
I don't know how to debug this bug (I don't familiar with Lisp)

Full log is in attachment

I use "gnucash 4.2-1" (archlinux)
Build ID: 4.2+(2020-09-26)
Comment 1 Christopher Lam 2020-11-20 11:16:47 EST
If you modify commodity-utilities.scm as follows, the https://wiki.gnucash.org/wiki/Tracefile will give valuable information.

(Hint: add the gnc:pk line)

modified   gnucash/report/commodity-utilities.scm
@@ -693,6 +693,7 @@
 ;; <gnc-monetary>.
 (define (gnc:exchange-by-pricedb-nearest
          foreign domestic date)
+  (gnc:pk foreign domestic date)
   (and (record? foreign)
        (gnc:gnc-monetary? foreign)
        date
Comment 2 mr.lequoctuan 2020-11-20 14:58:01 EST
After insert above line
I found the transaction that cause error

It is a 50 USD transaction, with exchange rate to VND
I try change the value to 51USD, cashflow work fine
Then I change back to orginal value, and it is ok now
Or if I save it as XML, it will be ok too (I use is sqlite backend)

I don't know what cause the problem, maybe because old gnucash version (year 2013)
Comment 3 mr.lequoctuan 2020-11-20 14:58:49 EST
Created attachment 373918 [details]
file cause bug

I send the minimum file that cause error
Comment 4 John Ralls 2020-11-20 22:50:23 EST
What options have you set for the cash flow report? The defaults seem to work fine on your attached file with the report currency either USD or VND.
Comment 5 Christopher Lam 2020-11-21 01:34:28 EST
I bet the original file has no VNDUSD price.
Comment 6 mr.lequoctuan 2020-11-21 02:51:45 EST
I just open default report, no option

If I create new user, problem is solved for that user
So the problem is in my machine

But I don't know what wrong
Because I try to recreate /home/<user>, or create new user with same UID, problem is still exists
Comment 7 Christopher Lam 2020-11-22 09:02:06 EST
See your price database; VND/USD has no price on 27/05/13. Not sure how you managed that. Could this be the cause?
Comment 8 Christopher Lam 2020-11-22 09:18:06 EST
Correct see the 2nd line of prices table:- USD/VND price is -1/0

SELECT * from "prices" LIMIT 8

9c7170a9f5a905e19e9692af80e53c26,44be3c71668990c68cf1cef43e2f6043,2a7c80f27f31d0e579f677494c9db001,20130522170000,user:xfer-dialog,,21360,1
9652742c363f649b7a41d3ed7106c361,44be3c71668990c68cf1cef43e2f6043,2a7c80f27f31d0e579f677494c9db001,20130526170000,user:xfer-dialog,,-1,0
4f280c73d0bd115150f1424cbf666619,44be3c71668990c68cf1cef43e2f6043,2a7c80f27f31d0e579f677494c9db001,20140430170000,user:xfer-dialog,,21000,1
01672a3cff500ef0dd07bd466f73230b,44be3c71668990c68cf1cef43e2f6043,2a7c80f27f31d0e579f677494c9db001,20140430170000,user:xfer-dialog,,440000,21
5fe6c490b7d4f91ce462fb9853d8e7b8,60aacdafa49dda93acc92dd0e0daa338,2a7c80f27f31d0e579f677494c9db001,20160216170000,user:price,transaction,160500000,10000
218b09ad6fb33aa195e38eb28887f8b8,60aacdafa49dda93acc92dd0e0daa338,2a7c80f27f31d0e579f677494c9db001,20160220170000,user:price-editor,,160500000,10000
8180466a7999f2ba568291bbd6ec52c2,44be3c71668990c68cf1cef43e2f6043,2a7c80f27f31d0e579f677494c9db001,20170426170000,user:xfer-dialog,transaction,227666667,10000
0c4e3895f32e57be0e7b7c671df90af1,44be3c71668990c68cf1cef43e2f6043,2a7c80f27f31d0e579f677494c9db001,20170503170000,user:price,,227666667,10000
Comment 9 Christopher Lam 2020-11-22 09:32:48 EST
To reproduce bug:

startdate - april-2013
enddate - june-2013
currency - VND

Here's a fix which returns price=0 when price at date is invalid. I think this is safe.

@@ -2592,6 +2592,9 @@ gnc_pricedb_get_nearest_price (GNCPriceDB *pdb,
     if (gnc_numeric_zero_p (price))
         price = indirect_price_conversion (pdb, orig_currency, new_currency, t);
 
+    if (gnc_numeric_check (price))
+        return gnc_numeric_zero ();
+
     return gnc_numeric_reduce (price);
 }
Comment 10 Christopher Lam 2020-11-22 10:11:30 EST
Better fix -- gnc_pricedb_get_nearest_price may still return invalid gnc_numeric; convert_amount_at_date return gnc_numeric_zero if price is invalid.

modified   libgnucash/engine/gnc-pricedb.c
@@ -2616,6 +2616,10 @@ static gnc_numeric convert_amount_at_date (GNCPriceDB *pdb,
 
     price = gnc_pricedb_get_nearest_price (pdb, orig_currency, new_currency, t);
 
+    /* some prices are invalid. return zero instead. see 798015 */
+    if (gnc_numeric_check (price))
+        return gnc_numeric_zero ();
+
     return gnc_numeric_mul
         (amount, price, gnc_commodity_get_fraction (new_currency),
          GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND);
Comment 11 Christopher Lam 2020-11-22 10:37:15 EST
fixed in maint. Please build from latest, or latest flatpak from tomorrow onwards
https://code.gnucash.org/builds/flatpak/maint/

Note You need to log in before you can comment on or make changes to this bug.