P.S. if the "bad" XML file is saved as sqlite3 it stays bad, i.e. saving
as sqlite3 and then back to xml doesn't fix the issue.
Wm
On 2026-09-30 11:20, Wm Tarr wrote:
What a fascinating bug, good detective work, Lance.
I can reproduce this on XML and also say it doesn't happen with
sqlite3 using 5.16 on Windows 10 Pro.
Wm
On 2026-09-30 03:53, Lance Booth via gnucash-user wrote:
Hello,
I'm using GnuCash 5.17 on Windows with the XML backend, though this
problem goes back earlier than 5.17. I tried to start using Lots in
my book that I've used heavily for years and I discovered an unusual
problem. Whenever I used the "scrub account" button and assigned an
income account to the resulting "Realized gain/loss" splits, it
seemed to work. But the next time I loaded up GnuCash and tried to
scrub the account again because of new entries, it duplicated all my
existing gain/loss splits. This happened with every single one of the
security accounts I tried it with.
I eventually figured out what causes this. If the gain/loss
transactions are located earlier in the XML than the other
transactions in the security account, that's enough to cause this
problem. If you were to inspect the XML after this duplication bug,
you'd find the old gain/loss splits have "gains-split" entries
pointing back to its associated sale split, but the sale split's
"gains-source" instead points back to the new duplicate gain/loss
split. Since GnuCash saves transactions in account order, this can
only happen when the income account is loaded BEFORE the Assets
account in GnuCash (or if you assign the "Realized gain/loss" account
to something in Assets that you know will be loaded before your
security account.)
Steps to reproduce:
1. Create a new book, either skipping the account templates or using
one that has the top level Income account but NOT the top level
Assets account.
2. Create the Income and Assets top level accounts, in that order.
3. Create a security in the security editor, a stock account under
Assets, and a gains account under Income. Add a bank account (or
something) under assets as well.
4. Enter a buy transaction followed by a sell transaction in the
security account. The sell transaction should be at a later date than
the buy transaction (I'll explain why later.)
5. Open the lots editor, and click "Scrub account". As you normally
might, change the account of the resulting gain/loss split to
Income:gains.
6. Save, close, and reopen. Open the lots editor again and click
"Scrub account". The gain/loss transaction should duplicate. Step 6
can be repeated every time you save, close, and reopen.
I have a lot of saved report configs, scheduled transactions, etc.
and didn't want to create a new book to try and dodge this bug.
Fortunately, the fix is easy: just open the XML file, cut all the
Assets accounts, and paste them at the very top of the accounts
entries. Assuming you have all your security accounts in Assets, this
completely fixes the problem. IMPORTANT: You should then open your
book, save it (just make a dummy transaction), and close it again. At
that point, GnuCash will have written your transactions to the file
in proper order. You can also temporarily fix this problem by moving
the gain/loss transactions themselves to the END of the file, and
that actually works, but only for the next run because the
transaction order is overwritten when GnuCash saves.
I suspect not many people will have this issue given how likely it is
to have the Assets account created first during the new book wizard,
but somehow it happened to me, and it took quite a lot of time to
figure it out. Anyway, could I get a Bugzilla account so I can report
this properly?
Lance
_______________________________________________
gnucash-user mailing list
[email protected]
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.
_______________________________________________
gnucash-user mailing list
[email protected]
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.
_______________________________________________
gnucash-user mailing list
[email protected]
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.