TheAxelander / OpenBudgeteer

OpenBudgeteer is a budgeting app based on the Bucket Budgeting Principle
https://theaxelander.github.io
MIT License
745 stars 42 forks source link

Inconsistent database state when assigning transactions via rules to invalid buckets #254

Open ramonwenger opened 1 month ago

ramonwenger commented 1 month ago

Describe the bug First of all, I didn't realize that buckets are only valid from the month they were first created in. So I started with an import of my transactions of the last 6 months, and then started creating buckets and assigning transaction from the current month (June). I then started creating rules, which helped me using the "Propose Buckets" button, that then suggested the correct bucket.

When going back a month to May, the buckets did not exist / were not valid, so I couldn't choose them, but when using the "Propose Buckets" button, I could still choose the buckets defined in the rules, and save them. But, when returning to the month in question (May in my example), the UI returns an error, saying "Error during loading: Sequence contains no matching element". No transaction for May get displayed then, and I can't edit any transactions from May any more (April is fine again).

I assume that this has to do with the UI trying to display transactions that have invalid buckets, and then crashing. I cannot get out of this state though, as I can't remove the offending buckets from the transactions, so I'm afraid my database is in a bad state right now.

To Reproduce Steps to reproduce the behavior:

  1. Create bucket in a certain month (e.g. June)
  2. Create a transaction in said month
  3. Create a rule to match this transaction to that bucket
  4. Go back a month (e.g. May)
  5. Create a transaction matching the rule
  6. Use "Propose Bucket" to then assign the transaction from earlier month to bucket in later month
  7. Try to go to earlier month after a reload
  8. The application should now display "Error during loading: Sequence contains no matching element"

Expected behavior Let me assign newer buckets to older transactions and change the valid from date (or make it explicit), or prevent rules using invalid buckets for the current month from being applied.

Additional helpful details

TheAxelander commented 1 month ago

Thanks for you detailed reporting. Indeed that should not happen that Buckets which are not valid (yet) can be selected.

For intermediate help, my proposal would be to delete everything in table BudgetedTransaction, which should remove all Bucket assignments and let you again edit the transactions in UI. For your Bucket setup either recreate them in the very first month on where you will start importing transactions. Alternatively you can also modify the ValidFrom date in the database. This would need to be updated in table Bucket and BucketVersion

ramonwenger commented 1 month ago

Thank you @TheAxelander for the quick reply. I already started fresh with a new database, but if it's of any help I can try to fix my old database, just to see if the fix works.