Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/basyx/aas/backend/local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def discard(self, x: model.Identifiable) -> None:
except FileNotFoundError as e:
raise KeyError("No AAS object with id {} exists in local file database".format(x.id)) from e
with self._object_cache_lock:
del self._object_cache[x.id]
self._object_cache.pop(x.id, None)

def __contains__(self, x: object) -> bool:
"""
Expand Down
14 changes: 0 additions & 14 deletions sdk/basyx/aas/model/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@ def sync(self, other: Iterable[_VALUE], overwrite: bool) -> Tuple[int, int, int]
for value in other:
if value in self:
if overwrite:

# TODO: This is a quick fix. Yes it works. The underlying problem with the subclass
# `LocalFileIdentifiableStore` will be solved in a separate issue
# (https://github.com/eclipse-basyx/basyx-python-sdk/issues/438).
# Think of this as pythonic duct tape.
#
# The problem is that the `_object_cache` isn't initialised together with the
# `LocalFileIdentifiableStore`, leading to an error when `discard()` is called on the empty cache.
# The for-loop calls `__iter__` calls `get_identifiable_by_hash()` calls
# `self._object_cache[obj.id] = obj`, adding all identifiables to the cache and therefore avoiding
# the error.
for element in self:
pass

self.discard(value)
self.add(value)
overwritten += 1
Expand Down
10 changes: 10 additions & 0 deletions sdk/test/backend/test_local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ def test_key_errors(self) -> None:
self.identifiable_store.discard(retrieved_submodel)
self.assertEqual("'No AAS object with id https://acplt.org/Test_Submodel exists in "
"local file database'", str(cm.exception))

def test_reload_discard(self) -> None:
# Load example submodel
example_submodel = create_example_submodel()
self.identifiable_store.add(example_submodel)

# Reload the DictIdentifiableStore and discard the example submodel
self.identifiable_store = local_file.LocalFileIdentifiableStore(store_path)
self.identifiable_store.discard(example_submodel)
self.assertNotIn(example_submodel, self.identifiable_store)