Skip to content

Commit

Permalink
Fix tests getting stuck because of preemptively deleted listeners
Browse files Browse the repository at this point in the history
When a locked db failed to commit the listener would still be deleted, leading to weird behaviour in the db editor.

Re #2201
  • Loading branch information
Henrik Koski committed Aug 18, 2023
1 parent 4c8ced9 commit 68906b8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions spinetoolbox/spine_db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,21 +515,28 @@ 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)
self.undo_stack[db_map].canUndoChanged.disconnect(listener.update_undo_redo_actions)
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)
Expand Down

0 comments on commit 68906b8

Please sign in to comment.