Skip to content

Commit 8feebf0

Browse files
committed
fix: LocalFileIdentifiableStore.__iter__ filter non-.json files and use removesuffix
1 parent 148bd85 commit 8feebf0

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

sdk/basyx/aas/backend/local_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ def __iter__(self) -> Iterator[model.Identifiable]:
161161
"""
162162
logger.debug("Iterating over objects in database ...")
163163
for name in os.listdir(self.directory_path):
164-
yield self.get_identifiable_by_hash(name.rstrip(".json"))
164+
if name.endswith(".json"):
165+
yield self.get_identifiable_by_hash(name.removesuffix(".json"))
165166

166167
@staticmethod
167168
def _transform_id(identifier: model.Identifier) -> str:

sdk/test/backend/test_local_file.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ def test_key_errors(self) -> None:
107107
self.assertEqual("'No AAS object with id https://example.org/Test_Submodel exists in "
108108
"local file database'", str(cm.exception))
109109

110+
def test_iter_ignores_non_json_files(self) -> None:
111+
example_data = create_full_example()
112+
for item in example_data:
113+
self.identifiable_store.add(item)
114+
115+
# Stray files must not crash the iterator or be yielded
116+
stray = os.path.join(store_path, ".DS_Store")
117+
with open(stray, "w") as f:
118+
f.write("stray")
119+
items = list(self.identifiable_store)
120+
self.assertEqual(5, len(items))
121+
os.remove(stray)
122+
110123
def test_reload_discard(self) -> None:
111124
# Load example submodel
112125
example_submodel = create_example_submodel()

0 commit comments

Comments
 (0)