diff --git a/spinedb_api/db_mapping_base.py b/spinedb_api/db_mapping_base.py index a612bd03..c80fb985 100644 --- a/spinedb_api/db_mapping_base.py +++ b/spinedb_api/db_mapping_base.py @@ -2019,7 +2019,9 @@ def _reset_mapping(self): self.connection.execute(table.delete()) self.connection.execute("INSERT INTO alternative VALUES (1, 'Base', 'Base alternative', null)") - def make_cache(self, tablenames, include_descendants=False, include_ancestors=False, force_tablenames=None): + def make_cache( + self, tablenames, include_descendants=False, include_ancestors=False, force_tablenames=None, keep_existing=False + ): if include_descendants: tablenames |= { descendant for tablename in tablenames for descendant in self.descendant_tablenames.get(tablename, ()) @@ -2031,7 +2033,7 @@ def make_cache(self, tablenames, include_descendants=False, include_ancestors=Fa if force_tablenames: tablenames |= force_tablenames for tablename in tablenames & self.cache_sqs.keys(): - self._do_advance_cache_query(tablename) + self._do_advance_cache_query(tablename, keep_existing) return self.cache def _advance_cache_query(self, tablename, callback=None): @@ -2043,10 +2045,10 @@ def _advance_cache_query(self, tablename, callback=None): callback() return advanced - def _do_advance_cache_query(self, tablename): + def _do_advance_cache_query(self, tablename, keep_existing=False): table_cache = self.cache.table_cache(tablename) for x in self.query(getattr(self, self.cache_sqs[tablename])).yield_per(1000).enable_eagerloads(False): - table_cache.add_item(x._asdict()) + table_cache.add_item(x._asdict(), keep_existing) def _items_with_type_id(self, tablename, *items): type_id = { diff --git a/spinedb_api/db_mapping_remove_mixin.py b/spinedb_api/db_mapping_remove_mixin.py index f4718a3f..5c2cf779 100644 --- a/spinedb_api/db_mapping_remove_mixin.py +++ b/spinedb_api/db_mapping_remove_mixin.py @@ -83,6 +83,7 @@ def cascading_ids(self, cache=None, **kwargs): force_tablenames={"entity_metadata", "parameter_value_metadata"} if any(x in kwargs for x in ("entity_metadata", "parameter_value_metadata", "metadata")) else None, + keep_existing=True, ) ids = {} self._merge(ids, self._object_class_cascading_ids(kwargs.get("object_class", set()), cache))