Skip to content

Commit 55e75dd

Browse files
committed
server: Call \commit()\ after every mutation in repository
Previously, all mutating handlers in the repository called \`Referable.commit()\` to persist changes back to the underlying storage. This was removed in #370 together with the \`Backend\` concept, leaving mutations silently un-persisted to disk when using \`LocalFileIdentifiableStore\`. Each of the mutating handlers now calls \`self.object_store.commit()\` on the top-level \`Identifiable\` after any in-memory mutation, restoring the write-back behaviour that was lost in #370.
1 parent 6084f69 commit 55e75dd

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

server/app/interfaces/repository.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ def put_aas(self, request: Request, url_args: Dict, response_t: Type[APIResponse
559559
aas.update_from(
560560
HTTPApiDecoder.request_body(request, model.AssetAdministrationShell, is_stripped_request(request))
561561
)
562+
self.object_store.commit(aas)
562563
return response_t()
563564

564565
def delete_aas(self, request: Request, url_args: Dict, response_t: Type[APIResponse], **_kwargs) -> Response:
@@ -577,6 +578,7 @@ def put_aas_asset_information(
577578
) -> Response:
578579
aas = self._get_shell(url_args)
579580
aas.asset_information = HTTPApiDecoder.request_body(request, model.AssetInformation, False)
581+
self.object_store.commit(aas)
580582
return response_t()
581583

582584
def get_aas_submodel_refs(
@@ -595,6 +597,7 @@ def post_aas_submodel_refs(self, request: Request, url_args: Dict, response_t: T
595597
if sm_ref in aas.submodel:
596598
raise Conflict(f"{sm_ref!r} already exists!")
597599
aas.submodel.add(sm_ref)
600+
self.object_store.commit(aas)
598601
created_resource_url = map_adapter.build(self.delete_aas_submodel_refs_specific, {
599602
"aas_id": aas.id,
600603
"submodel_id": sm_ref.key[0].value
@@ -606,6 +609,7 @@ def delete_aas_submodel_refs_specific(
606609
) -> Response:
607610
aas = self._get_shell(url_args)
608611
aas.submodel.remove(self._get_submodel_reference(aas, url_args["submodel_id"]))
612+
self.object_store.commit(aas)
609613
return response_t()
610614

611615
def put_aas_submodel_refs_submodel(
@@ -619,9 +623,11 @@ def put_aas_submodel_refs_submodel(
619623
id_changed: bool = submodel.id != new_submodel.id
620624
# TODO: https://github.com/eclipse-basyx/basyx-python-sdk/issues/216
621625
submodel.update_from(new_submodel)
626+
self.object_store.commit(submodel)
622627
if id_changed:
623628
aas.submodel.remove(sm_ref)
624629
aas.submodel.add(model.ModelReference.from_referable(submodel))
630+
self.object_store.commit(aas)
625631
return response_t()
626632

627633
def delete_aas_submodel_refs_submodel(
@@ -632,6 +638,7 @@ def delete_aas_submodel_refs_submodel(
632638
submodel = self._resolve_reference(sm_ref)
633639
self.object_store.remove(submodel)
634640
aas.submodel.remove(sm_ref)
641+
self.object_store.commit(aas)
635642
return response_t()
636643

637644
def aas_submodel_refs_redirect(
@@ -708,6 +715,7 @@ def get_submodels_reference(
708715
def put_submodel(self, request: Request, url_args: Dict, response_t: Type[APIResponse], **_kwargs) -> Response:
709716
submodel = self._get_submodel(url_args)
710717
submodel.update_from(HTTPApiDecoder.request_body(request, model.Submodel, is_stripped_request(request)))
718+
self.object_store.commit(submodel)
711719
return response_t()
712720

713721
def get_submodel_submodel_elements(
@@ -776,6 +784,7 @@ def post_submodel_submodel_elements_id_short_path(
776784
f"SubmodelElement with idShort {new_submodel_element.id_short} already exists " f"within {parent}!"
777785
)
778786
submodel = self._get_submodel(url_args)
787+
self.object_store.commit(submodel)
779788
id_short_path = url_args.get("id_shorts", [])
780789
created_resource_url = map_adapter.build(
781790
self.get_submodel_submodel_elements_id_short_path,
@@ -794,6 +803,7 @@ def put_submodel_submodel_elements_id_short_path(
794803
request, model.SubmodelElement, is_stripped_request(request) # type: ignore[type-abstract]
795804
)
796805
submodel_element.update_from(new_submodel_element)
806+
self.object_store.commit(self._get_submodel(url_args))
797807
return response_t()
798808

799809
def delete_submodel_submodel_elements_id_short_path(
@@ -802,6 +812,7 @@ def delete_submodel_submodel_elements_id_short_path(
802812
sm_or_se = self._get_submodel_or_nested_submodel_element(url_args)
803813
parent: model.UniqueIdShortNamespace = self._expect_namespace(sm_or_se.parent, sm_or_se.id_short)
804814
self._namespace_submodel_element_op(parent, parent.remove_referable, sm_or_se.id_short)
815+
self.object_store.commit(self._get_submodel(url_args))
805816
return response_t()
806817

807818
def get_submodel_submodel_element_attachment(self, request: Request, url_args: Dict, **_kwargs) -> Response:
@@ -854,6 +865,7 @@ def put_submodel_submodel_element_attachment(
854865
)
855866

856867
submodel_element.value = self.file_store.add_file(filename, file_storage.stream, submodel_element.content_type)
868+
self.object_store.commit(self._get_submodel(url_args))
857869
return response_t()
858870

859871
def delete_submodel_submodel_element_attachment(
@@ -876,6 +888,7 @@ def delete_submodel_submodel_element_attachment(
876888
pass
877889
submodel_element.value = None
878890

891+
self.object_store.commit(self._get_submodel(url_args))
879892
return response_t()
880893

881894
def get_submodel_submodel_element_qualifiers(
@@ -895,6 +908,7 @@ def post_submodel_submodel_element_qualifiers(
895908
if sm_or_se.qualifier.contains_id("type", qualifier.type):
896909
raise Conflict(f"Qualifier with type {qualifier.type} already exists!")
897910
sm_or_se.qualifier.add(qualifier)
911+
self.object_store.commit(self._get_submodel(url_args))
898912
created_resource_url = map_adapter.build(
899913
self.get_submodel_submodel_element_qualifiers,
900914
{
@@ -918,6 +932,7 @@ def put_submodel_submodel_element_qualifiers(
918932
raise Conflict(f"A qualifier of type {new_qualifier.type!r} already exists for {sm_or_se!r}")
919933
sm_or_se.remove_qualifier_by_type(qualifier.type)
920934
sm_or_se.qualifier.add(new_qualifier)
935+
self.object_store.commit(self._get_submodel(url_args))
921936
if qualifier_type_changed:
922937
created_resource_url = map_adapter.build(
923938
self.get_submodel_submodel_element_qualifiers,
@@ -937,6 +952,7 @@ def delete_submodel_submodel_element_qualifiers(
937952
sm_or_se = self._get_submodel_or_nested_submodel_element(url_args)
938953
qualifier_type = url_args["qualifier_type"]
939954
self._qualifiable_qualifier_op(sm_or_se, sm_or_se.remove_qualifier_by_type, qualifier_type)
955+
self.object_store.commit(self._get_submodel(url_args))
940956
return response_t()
941957

942958
# --------- CONCEPT DESCRIPTION ROUTES ---------
@@ -976,6 +992,7 @@ def put_concept_description(
976992
concept_description.update_from(
977993
HTTPApiDecoder.request_body(request, model.ConceptDescription, is_stripped_request(request))
978994
)
995+
self.object_store.commit(concept_description)
979996
return response_t()
980997

981998
def delete_concept_description(

0 commit comments

Comments
 (0)