@@ -232,24 +232,28 @@ def replace_object(self, path: str, payload: dict):
232232 str|exception: return the replaced resource or an exception in case of fault.
233233 """
234234 object_type = self ._get_type (payload , path = path )
235+ payload_to_write = payload
235236 # we assume no changes can be done on collections
236237 if "Collection" in object_type :
237238 raise CollectionNotSupported ()
238239 try :
239240 # 1. check the path target of the operation exists
240241 self .storage_backend .read (path )
241242 # 2. is needed first forward the request to the agent managing the object
242- self .objects_manager .forward_to_manager (SunfishRequestType .REPLACE , path , payload = payload )
243+ #self.objects_manager.forward_to_manager(SunfishRequestType.REPLACE, path, payload=payload)
244+ agent_response = self .objects_manager .forward_to_manager (SunfishRequestType .REPLACE , path , payload = payload )
245+ if agent_response :
246+ payload_to_write = agent_response
243247 # 3. Execute any custom handler for this object type
244- self .objects_handler .dispatch (object_type , path , SunfishRequestType .REPLACE , payload = payload )
248+ self .objects_handler .dispatch (object_type , path , SunfishRequestType .REPLACE , payload = payload_to_write )
245249 except ResourceNotFound :
246250 logger .error (logger .error (f"The resource to be replaced ({ path } ) does not exist." ))
247251 except AttributeError :
248252 # The object does not have a handler.
249253 logger .debug (f"The object { object_type } does not have a custom handler" )
250254 pass
251255 # 4. persist change in Sunfish tree
252- return self .storage_backend .replace (payload )
256+ return self .storage_backend .replace (payload_to_write )
253257
254258 def patch_object (self , path : str , payload : dict ):
255259 """Calls the correspondent patch function from the backend implementation.
@@ -261,6 +265,7 @@ def patch_object(self, path: str, payload: dict):
261265 str|exception: return the updated resource or an exception in case of fault.
262266 """
263267 # we assume no changes can be done on collections
268+ payload_to_write = payload
264269 obj = self .storage_backend .read (path )
265270 object_type = self ._get_type (obj , path = path )
266271 if "Collection" in object_type :
@@ -269,7 +274,10 @@ def patch_object(self, path: str, payload: dict):
269274 # 1. check the path target of the operation exists
270275 self .storage_backend .read (path )
271276 # 2. is needed first forward the request to the agent managing the object
272- self .objects_manager .forward_to_manager (SunfishRequestType .PATCH , path , payload = payload )
277+ #self.objects_manager.forward_to_manager(SunfishRequestType.PATCH, path, payload=payload)
278+ agent_response = self .objects_manager .forward_to_manager (SunfishRequestType .PATCH , path , payload = payload )
279+ if agent_response :
280+ payload_to_write = agent_response
273281 # 3. Execute any custom handler for this object type
274282 self .objects_handler .dispatch (object_type , path , SunfishRequestType .PATCH , payload = payload )
275283 except ResourceNotFound :
@@ -280,7 +288,7 @@ def patch_object(self, path: str, payload: dict):
280288 pass
281289
282290 # 4. persist change in Sunfish tree
283- return self .storage_backend .patch (path , payload )
291+ return self .storage_backend .patch (path , payload_to_write )
284292
285293 def delete_object (self , path : string ):
286294 """Calls the correspondent remove function from the backend implementation. Checks that the path is valid.
0 commit comments