Skip to content

Commit

Permalink
Fix segfault in Database editor (#2489)
Browse files Browse the repository at this point in the history
  • Loading branch information
soininen authored Jan 15, 2024
2 parents 921f400 + 2336411 commit 2fc2933
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data.csv": ["output\\base_scenario_e7cb0c670df62a5135b1dd6236afee47eaaad217\\data.csv"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
base_scenario - Test data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VisibleByDefault,visible
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"items": {
"Test data": {
"url": {
"username": "",
"password": ""
}
},
"Exporter": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Tool": {
"Run SpineOpt": {
"execution_settings": {}
},
"Load template": {
"execution_settings": {}
},
"Run SpineOpt detached": {
"execution_settings": {}
}
}
}
2 changes: 1 addition & 1 deletion spinetoolbox/mvcmodels/minimal_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def insert_children(self, position, children):
"""
bad_types = [type(child) for child in children if not isinstance(child, TreeItem)]
if bad_types:
raise TypeError(f"Can't insert children of type {bad_types} to an item of type {type(self)}")
raise TypeError(f"Can't insert children of type {bad_types} to an item of type {type(self).__name__}")
if position < 0 or position > self.child_count():
return False
self._polish_children(children)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def deep_take_db_map(self, db_map):
def deep_merge(self, other):
"""Merges another item and all its descendants into this one."""
if not isinstance(other, type(self)):
raise ValueError(f"Can't merge an instance of {type(other)} into a MultiDBTreeItem.")
raise ValueError(f"Can't merge an instance of {type(other).__name__} into a MultiDBTreeItem.")
for db_map in other.db_maps:
self.add_db_map_id(db_map, other.db_map_id(db_map))
self._merge_children(other.children)
Expand Down
11 changes: 7 additions & 4 deletions spinetoolbox/spine_db_editor/mvcmodels/multi_db_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __init__(self, db_editor, db_mngr, *db_maps):
self.db_editor = db_editor
self.db_mngr = db_mngr
self.db_maps = db_maps
self._invisible_root_item = TreeItem(self)
self.destroyed.connect(lambda obj=None: self._invisible_root_item.tear_down_recursively())
self._root_item = None

@property
Expand All @@ -52,12 +54,13 @@ def _header_labels(self):

def build_tree(self):
"""Builds tree."""
self.beginResetModel()
self._invisible_root_item = TreeItem(self)
self.destroyed.connect(lambda obj=None: self._invisible_root_item.tear_down_recursively())
if self._invisible_root_item.has_children():
self.beginRemoveRows(QModelIndex(), 0, self.rowCount() - 1)
self._invisible_root_item = TreeItem(self)
self.destroyed.connect(lambda obj=None: self._invisible_root_item.tear_down_recursively())
self.endRemoveRows()
self._root_item = self.root_item_type(self, dict.fromkeys(self.db_maps))
self._invisible_root_item.append_children([self._root_item])
self.endResetModel()

def columnCount(self, parent=QModelIndex()):
return len(self._header_labels)
Expand Down

0 comments on commit 2fc2933

Please sign in to comment.