Skip to content

sdk/basyx/aas/backend/local_file.py: Fix LocalFileObjectStore initialisation #438

@moritzsommer

Description

@moritzsommer

Current Situation

The object cache of the LocalFileObjectStore is not initialised when a new instance of the class is created. This means that the files it is intended to contain are not loaded initially.

def __init__(self, directory_path: str):
"""
Initializer of class LocalFileObjectStore
:param directory_path: Path to the local file backend (the path where you want to store your AAS JSON files)
"""
self.directory_path: str = directory_path.rstrip("/")
# A dictionary of weak references to local replications of stored objects. Objects are kept in this cache as
# long as there is any other reference in the Python application to them. We use this to make sure that only one
# local replication of each object is kept in the application and retrieving an object from the store always
# returns the **same** (not only equal) object. Still, objects are forgotten, when they are not referenced
# anywhere else to save memory.
self._object_cache: weakref.WeakValueDictionary[model.Identifier, model.Identifiable] \
= weakref.WeakValueDictionary()
self._object_cache_lock = threading.Lock()

Consequently, calling CRUD operations such as discard() on newly initialised instances raises a KeyError.

Proposed Change

Add an initialisation routine to the constructor that adds all local files of the LocalFileObjectStore to its cache from initialisation onwards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions