Closed jackrua closed 5 months ago
Hi! If you want I can assign this issue to you while you try to figure out the root cause of the bug. Since the issue might go unnoticed for a bit if you want you can try asking the same question also in the Discord channel since it is a bit more active
Finally found it! It took me more than I would like to admit. But contrary to my first hunch, the issue was in the SQL query in the selectAll()
method in BankAccountMethods
.
This method launches an SQL query that looks something like this:
SELECT b.*, (b.startingValue +
SUM(CASE WHEN t.type = 'IN' OR t.type = 'TRSF' AND t.idBankAccountTransfer = b.id THEN t.amount
ELSE 0 END) -
SUM(CASE WHEN t.type = 'OUT' OR t.type = 'TRSF' AND t.idBankAccount = b.id THEN t.amount
ELSE 0 END)
) as total
FROM bankAccount as b
LEFT JOIN "transaction" as t ON t.idBankAccount = b.id OR t.idBankAccountTransfer = b.id
WHERE active = 1 AND recurring = 0
GROUP BY b.id
ORDER BY createdAt AS
Now, focusing on the LEFT JOIN
part of the query, you see that the WHERE
clause filters out rows after the join is done, hence filtering out all bank accounts that have a transaction with the recurring field different from 0.
Practically speaking, if I add a new bank account that has no transactions (i.e. I add a row to the bankAccount table) this is correctly saved by the left join but is lost after it meets the WHERE
clause.
Hopefully, I will fix it tomorrow!
This issue has already been fixed in #134, forgot to git pull and have been using an older version of the repo.
Good catch by the way!
To reproduce the issue go to:
Settings
>Your accounts
>Add account
> (insert any name and value you want) >Create account
> Go back and you won't see any new account.What I have gathered so far
This is a really interesting bug that brought me to discover some of the internal logic of the app, but I can't really get to the bottom of it.
It seems to me that the
sossoldi.db
is actually updated when you trigger this action, however theaccountsList
variable (in the_AccountListState
object) is not updated, so it doesn't show up in the widget.When you add an account, the stack goes like this:
accountsList
watchesaccountsProvider
which is theAsyncAccountsNotifier()
notifierBankAccountMethods
object to interface with the db. Here everything seems to work (hence why the db is updated when you add the account)So I would say that the issue lies in
1.
. However when you update an account everything works as it should, so in this class (AsyncAccountsNotifier()
)updateAccount()
works, whileaddAccount()
doesn't.If anybody, more experienced than me, could point me in the right direction I would love to close this PR.