GNOME Bugzilla – Bug 569735
Don't create a new nested template root account when a file is opened
Last modified: 2018-06-29 22:17:01 UTC
Whenever an XML file is opened, Gnucash creates a new template root account and makes the old one a child of it. My main accounts file had them nested over 540 deep before I got annoyed enough to fix this. The problem is that sxtg_book_begin creates a root account when the book is opened. Then add_template_transaction_local tries to replace this new root account with the one read from the file. However the code that does this is rather badly broken and the result is that the one read from the file becomes a child of the one created in sxtg_book_begin.
Created attachment 127497 [details] [review] Patch to avoid creating nested root accounts This patch avoids creating any more nested root accounts, but it doesn't get rid of the ones that are already there. This is slightly more tricky than just deleting them since, although most of them have no children (other than the next root account), some do. Accounts created for template transactions will be children of whatever root account happens to be at the top of the tree then. As the file is saved and reopened, this will get pushed down into the tree of accounts. In my case about 5 of the 540 or so root accounts had other children.
trunk, r17868
branches, r17922. Thanks a lot, Mike!
Created attachment 275240 [details] Script to fix GnuCash XML files affected by this issue
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=569735. Please update any external references or bookmarks.