From b109e3ce204f83a2336b075df4d23d3684870f7a Mon Sep 17 00:00:00 2001 From: Johannes Nussbaum <39048939+jnussbaum@users.noreply.github.com> Date: Tue, 11 Jul 2023 16:27:22 +0200 Subject: [PATCH] fix(xmlupload): make sure resources aren't created multiple times after timeout error (DEV-2412) #432 If the network connection is very slow, it can happen that the client raises a timeout error, while the API is still processing the request. Because the client has only a temporary identifier of the resource, but no IRI, it is possible to create the same resource multiple times. The solution is to set the timeout to None, and to wait until the response is available, even if this takes very long. --- src/dsp_tools/models/connection.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/dsp_tools/models/connection.py b/src/dsp_tools/models/connection.py index 229b24b28..00fa9a395 100644 --- a/src/dsp_tools/models/connection.py +++ b/src/dsp_tools/models/connection.py @@ -122,6 +122,11 @@ def post(self, path: str, jsondata: Optional[str] = None): :return: Response from server """ + # timeout must be None, + # otherwise the client can get a timeout error while the API is still processing the request + # in that case, the client's retry will fail, and the response of the original API call is lost + timeout = None + if path[0] != "/": path = "/" + path headers = None @@ -131,10 +136,10 @@ def post(self, path: str, jsondata: Optional[str] = None): response = requests.post( self._server + path, headers=headers, - timeout=5, + timeout=timeout, ) else: - response = requests.post(self._server + path, timeout=5) + response = requests.post(self._server + path, timeout=timeout) else: if self._token is not None: headers = {"Content-Type": "application/json; charset=UTF-8", "Authorization": "Bearer " + self._token} @@ -142,7 +147,7 @@ def post(self, path: str, jsondata: Optional[str] = None): self._server + path, headers=headers, data=jsondata, - timeout=5, + timeout=timeout, ) else: headers = {"Content-Type": "application/json; charset=UTF-8"} @@ -150,7 +155,7 @@ def post(self, path: str, jsondata: Optional[str] = None): self._server + path, headers=headers, data=jsondata, - timeout=5, + timeout=timeout, ) if self._log: if jsondata: