Bug 501591 - Error in function QMap<QString, MyMoneyPayee> MyMoneyStorageSql::fetchPayees(const QStringList&, bool) const : reading Payee
Summary: Error in function QMap<QString, MyMoneyPayee> MyMoneyStorageSql::fetchPayees(...
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: database (show other bugs)
Version: 5.1.92
Platform: Gentoo Packages Linux
: NOR grave
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-16 16:12 UTC by Marco Di Fresco
Modified: 2025-03-18 09:01 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.1.94
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Di Fresco 2025-03-16 16:12:13 UTC
I got today the update from 5.13 to 5.1.92 on my Gentoo PC. Unfortunately when I start it I get the following error:

Error in function QMap<QString, MyMoneyPayee> MyMoneyStorageSql::fetchPayees(const QStringList&, bool) const : reading Payee
Driver = QMYSQL, Host = 192.168.0.12, User = marco, Database = KMyMoney-CHF
Driver Error: 
Database Error No : 
Text: 
Error type 0
Executed: SELECT kmmPayees.id AS id, kmmPayees.name AS name, kmmPayees.reference AS reference,  kmmPayees.email AS email, kmmPayees.addressStreet AS addressStreet, kmmPayees.addressCity AS addressCity, kmmPayees.addressZipcode AS addressZipcode,  kmmPayees.addressState AS addressState, kmmPayees.telephone AS  telephone, kmmPayees.notes AS notes,  kmmPayees.defaultAccountId AS defaultAccountId, kmmPayees.matchData AS matchData, kmmPayees.matchIgnoreCase AS matchIgnoreCase,  kmmPayees.matchKeys AS matchKeys,  kmmPayeesPayeeIdentifier.identifierId AS identId,  kmmPayees.idPattern AS idPattern,  kmmPayees.urlTemplate AS urlTemplate FROM ( SELECT * FROM kmmPayees  ) kmmPayees  LEFT OUTER JOIN kmmPayeesPayeeIdentifier ON kmmPayees.Id = kmmPayeesPayeeIdentifier.payeeId  ORDER BY kmmPayees.id, kmmPayeesPayeeIdentifier.userOrder;
Query error No 1054: Unknown column 'kmmPayees.idPattern' in 'field list' QMYSQL: Unable to execute query
Error type 2 /var/tmp/portage/app-office/kmymoney-5.1.92_p20250306/work/kmymoney-17859b4f0b2a654c11e8e209fdc7ea097c7f4ea5/kmymoney/plugins/sql/mymoneystoragesql.cpp:1338

Dismissing the error window lead to a fresh (empty) KMyMoney; therefore I cannot access my accounting.
Comment 1 Jack 2025-03-16 18:10:41 UTC
A few more details to help focus on the cause:  was this an upgrade from 5.1.3?  What version of what database are you using?  (mariadb, mysql, ...) It shouldn't matter, but just in case.
Can you open the database with command-line sql?   If so, what columns do exist in the kmmPayees table?
I am also on Gentoo, but my mariadb database is a bit scrambled and it will take me some time before I can directly try to replicate the issue.
Comment 2 Marco Di Fresco 2025-03-16 18:56:19 UTC
llo,
A few notes as requested:

    it was an upgrade from 5.1.3;
    the DB is MariaDB 5.5.68 (it is on a NAS, so I don't think I can upgrade it outside NAS firmware updates);
    here the columns in kmmPayees:

        id
        name
        reference
        email
        addressStreet
        addressCity
        addressZipcode
        addressState
        telephone
        notes
        defaultAccountId
        matchData
        matchIgnoreCase
        matchKeys


Best regards.
Comment 3 Jack 2025-03-16 21:21:54 UTC
The field it can't find was added four months ago, but only in master branch, not the 5.1 branch, which is why it is not in your data.  In the short term, using any version of KMyMoney from the 5.1 branch should be able to read your existing database.  You can either dig up the 5.1.3 ebuild from git, or use the 5.1.3 appimage I mentioned above.  
Separately, we'll have to figure out why the new version didn't recognize that your database needed to be updated, and get that code added.
Comment 4 Marco Di Fresco 2025-03-16 22:04:32 UTC
(In reply to Jack from comment #3)
> The field it can't find was added four months ago, but only in master
> branch, not the 5.1 branch, which is why it is not in your data.  In the
> short term, using any version of KMyMoney from the 5.1 branch should be able
> to read your existing database.  You can either dig up the 5.1.3 ebuild from
> git, or use the 5.1.3 appimage I mentioned above.  
> Separately, we'll have to figure out why the new version didn't recognize
> that your database needed to be updated, and get that code added.

OK, thanks.

Should I also open a bug report on Gentoo? Since 5.1.92 is now the only version on their tree, other may have the same problem too and therefore they should revert back to 5.1.3 until migrating-version is available.
Comment 5 Jack 2025-03-16 22:48:09 UTC
Unfortunately, the available appimage kmymoney-5.1-3218-linux-gcc-x86_64.AppImage seems to have been created without the SQL plugin.  Sqlcipher is present, but not sql.
Comment 6 Jack 2025-03-16 22:49:41 UTC
I think that would be a good idea - but to re-add 5.1.3 as stable, and leave 5.1.92 as testing.  Including a link to this bug might also help them decide how to handle it.
Comment 7 Marco Di Fresco 2025-03-16 23:04:23 UTC
Done: https://bugs.gentoo.org/951486
Comment 8 Jack 2025-03-17 00:04:52 UTC
It appears commit 4c86b5b1 (Adding payee-based links in the memo field) added two columns to the kmmPayees table, but no way to add the columns to existing databases, such as would be saved by any version from the 5.1 branch, including the released 5.1.3.  This was only discovered because Gentoo just replaced 5.1.3 with 5.1.92 as the only available stable version.  In addition, (as noted in Comment #5) the available 5.1 appimage seems to have Sqlcypher as the ONLY available sql back end.  For now, it appears the only workaround would be to use 5.1.3 to save the database as an xml or kmy file, and then in 5.1.92 (or other version from master) re-save to the database.
Comment 9 Ralf Habacker 2025-03-17 09:09:56 UTC
(In reply to Jack from comment #8)
> It appears commit 4c86b5b1 (Adding payee-based links in the memo field)
> added two columns to the kmmPayees table, but no way to add the columns to
> existing databases

Is there a hook in the sql storage implementation to intercept the case that the database to be loaded is outdated and to be able to perform corresponding updates afterwards ?
Comment 10 Bug Janitor Service 2025-03-17 13:27:18 UTC
A possibly relevant merge request was started @ https://invent.kde.org/office/kmymoney/-/merge_requests/264
Comment 11 Ralf Habacker 2025-03-18 09:01:35 UTC
Git commit 17659e3283753e5ad77fb8023452cf48811c585c by Ralf Habacker.
Committed on 18/03/2025 at 07:59.
Pushed by habacker into branch 'master'.

Add missing sql database upgrade for kmmpayees table

With this commit the kmymoney database version has been updated to 13.
FIXED-IN:5.1.94

M  +1    -1    kmymoney/plugins/sql/mymoneydbdef.cpp
M  +41   -0    kmymoney/plugins/sql/mymoneystoragesql_p.h

https://invent.kde.org/office/kmymoney/-/commit/17659e3283753e5ad77fb8023452cf48811c585c