Skip to content

Commit b8bdd93

Browse files
authored
Fix PUT/DELETE submodel-element-by-id-short-path not persisting changes (#80)
* Fix PUT/DELETE submodel-element-by-id-short-path not persisting changes put_submodel_submodel_elements_id_short_path and delete_submodel_submodel_elements_id_short_path each fetched the submodel twice: once (indirectly) to locate/mutate the target element, and again to pass to object_store.commit(). For object stores that deserialize a fresh object graph on every get (e.g. Neo4jObjectStore), these are two distinct instances, so the mutation made on the first instance was never part of the object passed to commit() and the change was silently lost. Fetch the submodel once, navigate to the nested element within that same instance, mutate it, and commit that same submodel instance.
1 parent 9da157c commit b8bdd93

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

server/app/interfaces/repository.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,23 +830,25 @@ def post_submodel_submodel_elements_id_short_path(
830830
def put_submodel_submodel_elements_id_short_path(
831831
self, request: Request, url_args: Dict, response_t: Type[APIResponse], **_kwargs
832832
) -> Response:
833-
submodel_element = self._get_submodel_submodel_elements_id_short_path(url_args)
833+
submodel = self._get_submodel(url_args)
834+
submodel_element = self._get_nested_submodel_element(submodel, url_args["id_shorts"])
834835
# TODO: remove the following type: ignore comment when mypy supports abstract types for Type[T]
835836
# see https://github.com/python/mypy/issues/5374
836837
new_submodel_element = HTTPApiDecoder.request_body(
837838
request, model.SubmodelElement, is_stripped_request(request) # type: ignore[type-abstract]
838839
)
839840
submodel_element.update_from(new_submodel_element)
840-
self.object_store.commit(self._get_submodel(url_args))
841+
self.object_store.commit(submodel)
841842
return response_t()
842843

843844
def delete_submodel_submodel_elements_id_short_path(
844845
self, request: Request, url_args: Dict, response_t: Type[APIResponse], **_kwargs
845846
) -> Response:
846-
sm_or_se = self._get_submodel_or_nested_submodel_element(url_args)
847+
submodel = self._get_submodel(url_args)
848+
sm_or_se = self._get_nested_submodel_element(submodel, url_args["id_shorts"])
847849
parent: model.UniqueIdShortNamespace = self._expect_namespace(sm_or_se.parent, sm_or_se.id_short)
848850
self._namespace_submodel_element_op(parent, parent.remove_referable, sm_or_se.id_short)
849-
self.object_store.commit(self._get_submodel(url_args))
851+
self.object_store.commit(submodel)
850852
return response_t()
851853

852854
def get_submodel_submodel_element_attachment(self, request: Request, url_args: Dict, **_kwargs) -> Response:

0 commit comments

Comments
 (0)