Bug 411958 - Import fails with LANG=DE
Summary: Import fails with LANG=DE
Status: RESOLVED FIXED
Alias: None
Product: skrooge
Classification: Applications
Component: general (show other bugs)
Version: 2.19.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Guillaume DE BURE
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-16 09:02 UTC by Christoph Vogtländer
Modified: 2019-09-23 20:23 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Smaple CSV file (1.34 KB, text/csv)
2019-09-16 09:29 UTC, Christoph Vogtländer
Details
Traces.txt (118.29 KB, text/plain)
2019-09-18 11:31 UTC, Christoph Vogtländer
Details
Patch1 (1.20 KB, patch)
2019-09-22 22:56 UTC, Christoph Vogtländer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Vogtländer 2019-09-16 09:02:59 UTC
SUMMARY
Importing a CSV file fails when LANG=DE (my default LANG) is set. When starting skrooge with LANG=C the import works as expected. The CSV file is encoded in ISO8859-15

STEPS TO REPRODUCE
1. Import a ISO8859-15 encoded CSV file wile LNAG=DE is set

OBSERVED RESULT
[ERR-5]: Das Importieren der Datei „file:///.../account.csv“ ist fehlgeschlagen.
[ERR-5]: „SKGOperationObject::setParentAccount“ ist fehlgeschlagen, da das verknüpfte Objekt noch nicht in der Datenbank gespeichert wurde.

Freely translated:
[ERR-5]:  Import of file ... failed
[ERR-5]: „SKGOperationObject::setParentAccount“ failed because the linked object has not been saved in the database

EXPECTED RESULT
Import should work independently from the currently set locale

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux
KDE Plasma Version: 5.16.5
KDE Frameworks Version: 5.61.0
Qt Version: 5.13.1
Skrooge: 2.20.0
Comment 1 Stephane MANKOWSKI 2019-09-16 09:11:31 UTC
Could you provide a sample file?
Comment 2 Christoph Vogtländer 2019-09-16 09:29:37 UTC
Created attachment 122679 [details]
Smaple CSV file

Required import settings:
Date: ^Buchungstag
Payee: ^payee|^tiers|^.*Zahlungspflichtiger
Comment: ^comment|^libell?|^d?tail|^info|^Vorgang.*
Amount: ^value|^amount|^valeur|^montant|^credit|^debit|^Umsatz
Sign: ^sign|^sens
Unit: ^Währung
Debit values of "sign" column: ^S

The other regular expressions are still on their default value (and IMHO not relevant for this case)
Comment 3 Stephane MANKOWSKI 2019-09-17 21:28:16 UTC
Hi,

In a terminal, I did:
export LANG=DE
launch skrooge
set the settings as described
import the csv file in an empty document

Result: I didn't reproduce the issue.

Could you help me to reproduce it.
Comment 4 Christoph Vogtländer 2019-09-18 01:17:42 UTC
Sorry. My default LANG is "de_DE.UTF-8".

I can confirm that it works with LANG=DE but not with LANG=de_DE.UTF-8

I start skrooge for my test with:
$ LANG=de_DE.UTF-8 skrooge
Comment 5 Stephane MANKOWSKI 2019-09-18 09:13:25 UTC
Hi,

Even like this, I'm not able to reproduce it.
Are you sure that you do the import in an empty document?
Could you try to generate traces like this?
export SKGTRACE=5
LANG=de_DE.UTF-8 skrooge 2>&1 > traces.txt
Comment 6 Christoph Vogtländer 2019-09-18 11:31:16 UTC
Created attachment 122700 [details]
Traces.txt

As requested
Comment 7 Christoph Vogtländer 2019-09-18 11:32:29 UTC
Hi,

yes, I'm sure that the file is not empty
Comment 8 Stephane MANKOWSKI 2019-09-20 19:21:02 UTC
Nothing interesting in trace file.
I'm still not able to reproduce it.
The problem seems to be linked to the association of the account on the operation.
Could you help me to reproduce it?
Comment 9 Christoph Vogtländer 2019-09-22 19:17:01 UTC
The import also fails when importing into a completely new (empty) file. How can I help? I think I am able to compile skrooge myself in debug mode.
If you can give me some hints where to set some break points it would be helpful.
Comment 10 Christoph Vogtländer 2019-09-22 19:58:15 UTC
I can see that in skgoperationobject.cpp:153 the value of "newAccount" is "0" with LANG=de_DE.UTF-8 and "1" with LANG=C.

Unfortunately I cannot see what is happening inside "importFile()" because skrooge loads the plug-ins from /usr/lib/qt/plugins (no debug information there of course) rather than from my shadow directory used when compiling. I can see that KServiceTypeTrader is used to locate plug-ins. I'm not experienced with KDE API and a quick search did not reveal anything useful. How can I instruct skrooge to load plug-ins from a custom directory?
If possible I would like to avoid to install my compiled binaries into the system.
Comment 11 Stephane MANKOWSKI 2019-09-22 20:49:30 UTC
Hi,

In fact, the operation is created on an "non existing" account (newAccount=0). That's why, skrooge raises this error.

It's difficult to configure your system to point on local directory.
Personally, I never did it. I always install the debug version in my system.
This is not a problem. You can uninstall it and reinstall the "non debug" version. 

The difficulty will be: understand how the default account is created (put a break point in SKGImportExportManager::getDefaultAccount).
Comment 12 Christoph Vogtländer 2019-09-22 22:53:46 UTC
I was able to track down this issue. The problem is that my bank exports the field "Konto-Nr." (account number) without actually setting any value (see the sample CSV file). When importing with LANG=de_DE.UTF-8 the default regular expression for detecting the account per line is "^Konto" which matches the exported field at column 4 in the header data.
The bool "noAccountColumn" (skgimportplugincsv.cpp:447) is false in this case and no default account will be created/selected. When processing the "account" column, "val" is an empty string and no account will be created/set either (as "val != defAccount.getName()" in skgimportplugincsv.cpp:618 is true). Setting the parent account will fail, then. 

Starting skrooge with LANG=C will change the default regular expression to "^account" which then does not match anything in the CSV. "noAccountColumn" is true and a default account will be created before the import gets started. The import succeeds in this case.

IMHO this should be handled more gracefully as it is nearly impossible to understand the problem from the users perspective. Either the importer should show a more meaningful error message or, even better, should fall back to the default account (like when "noAccountColumn" is true) for lines with an empty "Account" value. I will provide a patch for the latter case.
Comment 13 Christoph Vogtländer 2019-09-22 22:56:20 UTC
Created attachment 122811 [details]
Patch1

Patch which creates/selects the default account when the value for "account" column in CSV file is empty
Comment 14 Stephane MANKOWSKI 2019-09-23 20:23:37 UTC
Git commit 0149f30f5e0e04702bcdf376fa6fece7ec1f3b25 by Stephane MANKOWSKI.
Committed on 23/09/2019 at 20:23.
Pushed by smankowski into branch 'master'.

Import CSV fails if account is empty

M  +1    -0    CHANGELOG
M  +7    -1    plugins/import/skrooge_import_csv/skgimportplugincsv.cpp
A  +17   -0    tests/input/skgtestimportcsv/411958.csv
M  +39   -9    tests/skgbankmodelertest/skgtestimportcsv.cpp

https://commits.kde.org/skrooge/0149f30f5e0e04702bcdf376fa6fece7ec1f3b25