spine-tools / Spine-Toolbox

Spine Toolbox is an open source Python package to manage data, scenarios and workflows for modelling and simulation. You can have your local workflow, but work as a team through version control and SQL databases.
https://www.tools-for-energy-system-modelling.org/
GNU Lesser General Public License v3.0
72 stars 17 forks source link

Database shows dirty when modifications are reverted manually instead of undo #2544

Open PiispaH opened 9 months ago

PiispaH commented 9 months ago

Having an empty db adding an item like entity class and then deleting it immediately causes the db to be in a state where there is nothing to commit but the undo stack isn't clean either. When the user then tries to close the editor, they get prompted to commit the "changes". If they choose to commit before exiting, an error occurs because there is indeed nothing to commit.

Should / is it possible to check if the undo stack has "traced back to the start" meaning that no changes have actually been made and in that case mark the database as not dirty? This would allow the user to still undo the changes but also close the editor without being prompted to commit non existing changes.

manuelma commented 9 months ago

Nice one @PiispaH - I think another option is not to error out if there is nothing to commit. I'm not sure why we do it - it may be very old legacy. Essentially, the commit action should make sure that the contents of the mapping are in synch with the contents of the DB. If there are no changes, then the above holds trivially so it's fine. What do you think? @jkiviluo @soininen ?

soininen commented 9 months ago

I think it is OK to error at "nothing to commit" on spinedb_api level because that might be interesting information (has helped me to find bugs in client code) but we could just ignore the error in DB editor.

One thing though: it might be confusing if user gets prompted for a commit message and the message never ends in the database so maybe we want to inform the user after all that nothing was committed. It need not be an error message, though.