From 68906b8d8d7aeaa75907dffdd05b0c6c9460bb84 Mon Sep 17 00:00:00 2001 From: Henrik Koski Date: Fri, 18 Aug 2023 10:24:21 +0300 Subject: [PATCH] Fix tests getting stuck because of preemptively deleted listeners When a locked db failed to commit the listener would still be deleted, leading to weird behaviour in the db editor. Re #2201 --- spinetoolbox/spine_db_manager.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/spinetoolbox/spine_db_manager.py b/spinetoolbox/spine_db_manager.py index ee7f2af15..3cde2b24a 100644 --- a/spinetoolbox/spine_db_manager.py +++ b/spinetoolbox/spine_db_manager.py @@ -515,14 +515,7 @@ def unregister_listener(self, listener, *db_maps, dirty_db_maps=None, commit_dir failed_db_maps (list): All the db maps that failed to commit """ failed_db_maps = list() - if dirty_db_maps: - if commit_dirty: - failed_db_maps = self.commit_session(commit_msg, *dirty_db_maps) - else: - self.rollback_session(*dirty_db_maps) for db_map in db_maps: - if db_map in failed_db_maps: - continue self.remove_db_map_listener(db_map, listener) try: self.undo_stack[db_map].canRedoChanged.disconnect(listener.update_undo_redo_actions) @@ -530,6 +523,20 @@ def unregister_listener(self, listener, *db_maps, dirty_db_maps=None, commit_dir self.undo_stack[db_map].cleanChanged.disconnect(listener.update_commit_enabled) except AttributeError: pass + if dirty_db_maps: + if commit_dirty: + failed_db_maps += self.commit_session(commit_msg, *dirty_db_maps) + else: + self.rollback_session(*dirty_db_maps) + # If some db maps failed to commit, reinstate their listeners + for db_map in failed_db_maps: + self.add_db_map_listener(db_map, listener) + try: + self.undo_stack[db_map].canRedoChanged.connect(listener.update_undo_redo_actions) + self.undo_stack[db_map].canUndoChanged.connect(listener.update_undo_redo_actions) + self.undo_stack[db_map].cleanChanged.connect(listener.update_commit_enabled) + except AttributeError: + pass for db_map in db_maps: if not self.db_map_listeners(db_map): self.close_session(db_map.db_url)