Skip to content

Commit

Permalink
Test branch for PR 421
Browse files Browse the repository at this point in the history
  • Loading branch information
trunk-io[bot] authored Dec 7, 2023
2 parents 4071fbb + 2e52565 commit 61131f7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/cript/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from cript.api.utils.helper_functions import _get_node_type_from_json
from cript.api.utils.save_helper import (
_fix_node_save,
_get_uuid_from_error_message,
_identify_suppress_attributes,
_InternalSaveValues,
)
Expand Down Expand Up @@ -813,7 +812,11 @@ def _internal_save(self, node, save_values: Optional[_InternalSaveValues] = None
response: Dict = requests.patch(url=f"{self._host}/{node.node_type_snake_case}/{str(node.uuid)}/", headers=self._http_headers, data=json_data, timeout=_API_TIMEOUT).json() # type: ignore
else:
response: Dict = requests.post(url=f"{self._host}/{node.node_type_snake_case}/", headers=self._http_headers, data=json_data, timeout=_API_TIMEOUT).json() # type: ignore
# if node.node_type != "Project":
# test_success: Dict = requests.get(url=f"{self._host}/{node.node_type_snake_case}/{str(node.uuid)}/", headers=self._http_headers, timeout=_API_TIMEOUT).json()
# print("XYZ", json_data, save_values, response, test_success)

# print(json_data, patch_request, response, save_values)
# If we get an error we may be able to fix, we to handle this extra and save the bad node first.
# Errors with this code, may be fixable
if response["code"] in (400, 409):
Expand All @@ -828,7 +831,6 @@ def _internal_save(self, node, save_values: Optional[_InternalSaveValues] = None
raise CRIPTDuplicateNameError(response, json_data, exc) from exc
# Else just raise the exception as normal.
raise exc

save_values += returned_save_values

# Handle errors from patching with too many attributes
Expand All @@ -841,12 +843,12 @@ def _internal_save(self, node, save_values: Optional[_InternalSaveValues] = None
# Aka we did something to fix the occurring error
if not save_values > old_save_values:
# TODO remove once get works properly
if not patch_request and response["code"] == 409 and response["error"].strip().startswith("Duplicate uuid:"): # type: ignore
duplicate_uuid = _get_uuid_from_error_message(response["error"]) # type: ignore
if str(node.uuid) == duplicate_uuid:
force_patch = True
continue

if not patch_request:
# and response["code"] == 409 and response["error"].strip().startswith("Duplicate uuid:"): # type: ignore
# duplicate_uuid = _get_uuid_from_error_message(response["error"]) # type: ignore
# if str(node.uuid) == duplicate_uuid:
force_patch = True
continue
break

if response["code"] != 200:
Expand Down

0 comments on commit 61131f7

Please sign in to comment.