Bug 406321 - ERR-8/ERR-5 importing qfx file, "More than one object returned in 'v_account' for 't_number='''"
Summary: ERR-8/ERR-5 importing qfx file, "More than one object returned in 'v_account'...
Status: RESOLVED FIXED
Alias: None
Product: skrooge
Classification: Applications
Component: general (show other bugs)
Version: 2.18.0
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Stephane MANKOWSKI
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-08 07:11 UTC by skierpage
Modified: 2019-04-24 03:25 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description skierpage 2019-04-08 07:11:48 UTC
SUMMARY
I tried to import a .qfx file of transactions from my credit card issuer. Two different files (different date ranges) both fail.

But if I import the same qfx files into a new Skrooge file, there's no error. One of the qfx files has transactions that match transactions I have already imported, the other may have a few transactions that match ones I added to Skrooge manually. If duplication is the problem I would expect to get the amber "NN operations not imported because they already exist" message.

STEPS TO REPRODUCE
 $ export SKGTRACE=15
 $ export SKGTRACESQL=1
 $ skrooge
 File > Import > Import qfx  file.

OBSERVED RESULT
Import quickly fails with
[ERR-5]: Import of file named 'file:///path/to.qfx' failed

in the trace output,

##        executeSqliteOrder:SELECT * FROM v_account WHERE t_number='' TIME=1 ms,  (with fetch):2 ms
##        <static int SKGImportPluginOfx::ofxStatementCallback(OfxStatementData, void*) RC=[ERR-8]: More than one object returned in 'v_account' for 't_number='''                
##        >virtual SKGError SKGDocument::endTransaction(bool)
##          >virtual int SKGDocument::getCurrentTransaction() const
##          <virtual int SKGDocument::getCurrentTransaction() const
##        <virtual SKGError SKGDocument::endTransaction(bool) RC=[SUC-0]
##      <virtual SKGError SKGImportPluginOfx::importFile() RC=[ERR-8]: More than one object returned in 'v_account' for 't_number='''                                             
##      >virtual SKGError SKGDocument::endTransaction(bool)
##        >virtual int SKGDocument::getCurrentTransaction() const
##        <virtual int SKGDocument::getCurrentTransaction() const
##      <virtual SKGError SKGDocument::endTransaction(bool) RC=[SUC-0]
##    <SKGError SKGImportExportManager::importFile() RC=[ERR-8]: More than one object returned in 'v_account' for 't_number='''   
...

EXPECTED RESULT
Successful import, or something more informative in Skrooge messages.

SOFTWARE/OS VERSIONS

Linux/KDE Plasma: 
KDE Plasma Version: 5.14.5
KDE Frameworks Version: 5.55.0
Qt Version: 5.11.3

ADDITIONAL INFORMATION
Downloading transactions yourself from a bank is much more fiddly than Quicken 2012's "One Step Update" which almost never grabbed duplicate transactions.
Comment 1 Stephane MANKOWSKI 2019-04-08 18:55:14 UTC
Hi,

Skrooge tries to find the most appropriate existing account to import the operation.
In you case, 2 accounts are already existing and without account number set.
In the imported file, the account_id seems to be empty, so Skrooge finds the 2 existing accounts as candidates. In the doubts, I prefer to raise an error.

Could you send me a qfx sample file (anonymized) to reproduce the error (I tried to build it manually but without success)?
Regards.
Comment 2 Stephane MANKOWSKI 2019-04-08 19:12:35 UTC
Hi,

Forget my previous request, I'm able to reproduce the issue.
Comment 3 Stephane MANKOWSKI 2019-04-08 21:49:59 UTC
Hi,

The issue it due to empty value is <ACCTID> in your qfx file.
I will try to find a solution.
Comment 4 Stephane MANKOWSKI 2019-04-09 18:34:17 UTC
Git commit 2471a3eadff09f3754e02f9e2745213c68ccb298 by Stephane MANKOWSKI.
Committed on 09/04/2019 at 18:34.
Pushed by smankowski into branch 'master'.

ERR-8/ERR-5 importing qfx file, "More than one object returned in 'v_account' for 't_number='''"

M  +1    -0    CHANGELOG
M  +17   -4    plugins/import/skrooge_import_ofx/skgimportpluginofx.cpp
M  +1    -0    plugins/import/skrooge_import_ofx/skgimportpluginofx.h
A  +92   -0    tests/input/skgtestimportofx/406321.ofx
A  +-    --    tests/input/skgtestimportofx/406321.skg
M  +13   -0    tests/skgbankmodelertest/skgtestimportofx.cpp

https://commits.kde.org/skrooge/2471a3eadff09f3754e02f9e2745213c68ccb298
Comment 5 skierpage 2019-04-10 00:04:40 UTC
(In reply to Stephane MANKOWSKI from comment #3)

> The issue it due to empty value is <ACCTID> in your qfx file.

There is an ACCTID in both qfx files, and it matches the Number field of one of the existing Credit card account in my Skrooge file. They're in the OFXSGML format VERSION 102 with many tags missing a matching closing tag, including ACCTID. There's also a <BANKNAME.BASICACCT> tag with the same number.

I tried changing the Number of the existing credit card account in a copy of my Skrooge file so that it wouldn't match, and import still failed with the same SQL error (and then Skrooge crashed with a double-free, I filed DrKonqi bug). I have one account without any Number, a cash wallet. I could try to delete stuff from my Skrooge file until import succeeds (again, importing the .qfx files into an empty file succeeded), but I'm not sure where to start.

> I will try to find a solution. (... then FIXED?)
Your are awesome, thanks so much! (I donated €10 to KDE e.V.)
Comment 6 skierpage 2019-04-11 05:38:20 UTC
I think I managed to build skrooge git master from source \o/ (`skrooge -v` reports "skrooge 2.19.0BETA"), and importing those two .qfx files gives me the same error and similar trace output.
Comment 7 Stephane MANKOWSKI 2019-04-11 07:00:00 UTC
(In reply to skierpage from comment #6)
> I think I managed to build skrooge git master from source \o/ (`skrooge -v`
> reports "skrooge 2.19.0BETA"), and importing those two .qfx files gives me
> the same error and similar trace output.

Did you install the new version (sudo make install) ?
If NO, the plugins used are the system ones, so the old ones.

You must install the new version if you want to be able to test it.
Regards.

Thank you for your donation.
Comment 8 skierpage 2019-04-12 02:48:28 UTC
(In reply to Stephane MANKOWSKI from comment #7)
> Did you install the new version (sudo make install) ?
I rebuilt the Skrooge 2.18 packages for Fedora 29 from Git master, which produced

$ ls -1 ~/rpmbuild/RPMS/x86_64
skrooge-debuginfo-master-0.fc29.x86_64.rpm
skrooge-debugsource-master-0.fc29.x86_64.rpm
skrooge-libs-debuginfo-master-0.fc29.x86_64.rpm
skrooge-libs-master-0.fc29.x86_64.rpm
skrooge-master-0.fc29.x86_64.rpm

and then I did `sudo dnf install ~/rpmbuild/RPMS/x86_64/skrooge-*.rpm` to install all of these.

> If NO, the plugins used are the system ones, so the old ones.
I think I only have my newly-built plugins, is there a way to check that they are the latest code? (Is there a version string in each one?).
$ ls -s -l `locate skrooge_import_ofx.so`
-rwxr-xr-x. 1 spage spage 2011968 Apr 10 19:13 /home/spage/rpmbuild/BUILD/skrooge-master/x86_64-redhat-linux-gnu/lib/skrooge_import_ofx.so
-rwxr-xr-x. 1 root  root   114208 Apr 10 19:14 /usr/lib64/qt5/plugins/skrooge_import_ofx.so
-rw-r--r--. 1 root  root  1510928 Apr 10 19:14 /usr/lib/debug/usr/lib64/qt5/plugins/skrooge_import_ofx.so-master-0.fc29.x86_64.debug

so I'm pretty sure this is entirely the new 2.19.0BETA code, but this is the first time I've done this ;-) .
Comment 9 Stephane MANKOWSKI 2019-04-12 16:22:41 UTC
Hi,

What you did seems to be OK!
Just to be sure, when you launch:
skrooge --version
do you have this ?
skrooge 2.19.0BETA

I did a new commit with more traces.
Could you do that?
1- build and install this new version
2- export SKGTRACE=3
3- skrooge > traces.txt 2>&1
4- do the import
5- Send me the generated traces by email (you can find it in the "About" of Skrooge).

Regards.
Comment 10 Stephane MANKOWSKI 2019-04-15 19:56:22 UTC
Do you have an answer?
Comment 11 skierpage 2019-04-18 06:19:00 UTC
(In reply to Stephane MANKOWSKI from comment #10)
> Do you have an answer?
Sorry I was busy doing taxes (with Skrooge, *love* the Group by > Category and Bookmarks > Bookmark current page > Rename). The trace now contains (I'll send the full trace separately):

##    >virtual SKGError SKGImportPluginOfx::importFile()
##      >static SKGError SKGImportPluginOfx::getAccount(OfxAccountData*, SKGDocumentBank*, SKGAccountObject&)                                                                     
##        >static QString SKGImportPluginOfx::getAccountName(OfxAccountData*)
##        accountNumber=
##        <static QString SKGImportPluginOfx::getAccountName(OfxAccountData*)
##      NOT found in index
##      <static SKGError SKGImportPluginOfx::getAccount(OfxAccountData*, SKGDocumentBank*, SKGAccountObject&) RC=[ERR-8]: More than one object returned in 'v_account' for 't_number='''                                                                                   
##    Add account 'Credit card ' in index
##      >static SKGError SKGImportPluginOfx::getAccount(OfxAccountData*, SKGDocumentBank*, SKGAccountObject&)                                                                     
##        >static QString SKGImportPluginOfx::getAccountName(OfxAccountData*)
##        accountNumber=
##        <static QString SKGImportPluginOfx::getAccountName(OfxAccountData*)
##      NOT found in index
##      <static SKGError SKGImportPluginOfx::getAccount(OfxAccountData*, SKGDocumentBank*, SKGAccountObject&) RC=[ERR-8]: More than one object returned in 'v_account' for 't_number='''

So it thinks the account number is blank. I described in comment #3 how it's in <ACCTID> and <{bankname}.BASICACCT>; these SGML tags are within the CCACCTFROM tag.
Comment 12 skierpage 2019-04-19 06:26:20 UTC
While reducing the test case, I discovered
WORKAROUND: problem goes away if I insert linebreaks between the SGML tags of the qfx file, which output all its SGML tags (<OFX><SIGNONMSGSRSV1><SONRS><STATUS>...) on one line.

The problem is in the LibOFX library that skrooge and other programs use to read OFX/QFX files, reported against GnuCash https://bugs.gnucash.org/show_bug.cgi?id=797081 , and fixed in LibOFX release 0.9.14:
     * Fix proprietary tags striping eating the content of the previous tag if
       proprietary tag is in the middle of the line.
Fedora 29 has version 0.9.13 of this library, hence Skrooge exhibits the bug.  If you install the 'ofx' package you can see that its `ofxdump` utility prints "Account ID: <blank>" in version 0.9.13, but if I build 0.9.14 it prints the correct account number from the OFX file.

So this bug is in a supporting library, and is fixed in a newer version of that library. Skrooge's behavior isn't ideal in that it doesn't warn about no account number and only fails if I have existing accounts in my .skg file, but the bug isn't its fault.
Comment 13 Stephane MANKOWSKI 2019-04-19 17:06:40 UTC
Git commit 600a94a733a4bb32b29e97329a36d9f34dc88b72 by Stephane MANKOWSKI.
Committed on 19/04/2019 at 17:06.
Pushed by smankowski into branch 'master'.

M  +3    -3    plugins/import/skrooge_import_ofx/skgimportpluginofx.cpp
A  +12   -0    tests/input/skgtestimportofx/406321_2.ofx
M  +14   -0    tests/skgbankmodelertest/skgtestimportofx.cpp

https://commits.kde.org/skrooge/600a94a733a4bb32b29e97329a36d9f34dc88b72
Comment 14 skierpage 2019-04-24 03:25:23 UTC
(In reply to Stephane MANKOWSKI from comment #13)
> Git commit 600a94a733a4bb32b29e97329a36d9f34dc88b72 by Stephane MANKOWSKI.

If I rebuild with this, run with the buggy libofx 0.9.13 and import my original troublesome file,
* there is no crash (good!)
* the trace still has accountNumber=[blank] (OK, the libofx bug)
* No Skrooge message about import, neither green, orange, nor red. There is just a "1 file successfully imported" in the footer (hmmm)
* all transactions import as operations on wallet "credit card" with no account number (expected)
* all the transactions have date 12/31/69 (BUG!)

I think this last regression is known bug 406741. I'll try the fixed version.