Spine-Toolbox
Spine-Toolbox copied to clipboard
Purging database while it is being fetched may end in a Traceback
I have a largish database which takes some time to load into the DB editor. If I purge e.g. the parameter value while data is still being fetched, I quite often end with a Traceback:
Traceback (most recent call last):
File "spinetoolbox\widgets\notification.py", line 219, in _push_notification
if self._settings.value(self._settings_key, defaultValue="2") != "2":
File "spinetoolbox\spine_db_commands.py", line 232, in redo
items = self.db_mngr.do_remove_items(self.db_map, self.item_type, self.ids, check=self._check)
File "spinetoolbox\helpers.py", line 136, in new_function
return func(*args, **kwargs)
File "spinetoolbox\spine_db_manager.py", line 1499, in do_remove_items
return worker.remove_items(item_type, ids, check)
File "spinetoolbox\helpers.py", line 136, in new_function
return func(*args, **kwargs)
File "spinetoolbox\spine_db_worker.py", line 267, in remove_items
items, errors = self._db_map.remove_items(item_type, *ids, check=check)
File "spinedb_api\db_mapping.py", line 716, in remove_items
return self._modify_items(lambda x: self.remove_item(item_type, x, check=check), *ids, strict=strict)
File "spinedb_api\db_mapping.py", line 513, in _modify_items
item, error = function(item)
File "spinedb_api\db_mapping.py", line 716, in <lambda>
return self._modify_items(lambda x: self.remove_item(item_type, x, check=check), *ids, strict=strict)
File "spinedb_api\db_mapping.py", line 693, in remove_item
removed_item = mapped_table.remove_item(item)
File "spinedb_api\db_mapping_base.py", line 671, in remove_item
for current_item in self.valid_values():
File "spinedb_api\db_mapping_base.py", line 422, in <genexpr>
return (x for x in self.values() if x.is_valid())
RuntimeError: dictionary changed size during iteration
The Traceback is not really surprising: another thread modifies a mapped table while we are iterating over it.
We could try fixing all those potential places where this might happen. Another option would be to disallow edits while the worker thread is fetching. The latter option sounds more appealing to me.