Skip to content

Commit

Permalink
Merge pull request #138 from skyflowapi/SK-1731-updated-update-interface
Browse files Browse the repository at this point in the history
SK-1731: Updated Update Record interface
  • Loading branch information
saileshwar-skyflow authored Nov 21, 2024
2 parents 1d91b3e + 03f507d commit a8a38f3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion samples/vault_api/update_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
)

# sample data
update_data = {'id': '<SKYFLOW_ID>', '<FIELD1>': '<VALUE1>'}
update_data = {'skyflow_id': '<SKYFLOW_ID>', '<FIELD1>': '<VALUE1>'}

update_request = UpdateRequest(table='TABLE_NAME', data=update_data)

Expand Down
7 changes: 2 additions & 5 deletions skyflow/utils/validations/_validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ def validate_get_request(logger, request):

def validate_update_request(logger, request):
skyflow_id = ""
field = {key: value for key, value in request.data.items() if key != "id"}
field = {key: value for key, value in request.data.items() if key != "skyflow_id"}

try:
skyflow_id = request.data.get("id")
skyflow_id = request.data.get("skyflow_id")
except Exception:
log_error_log(SkyflowMessages.ErrorLogs.SKYFLOW_ID_IS_REQUIRED.value.format("UPDATE"), logger=logger)

Expand Down Expand Up @@ -499,9 +499,6 @@ def validate_update_request(logger, request):
SkyflowMessages.Error.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_STRICT_ENABLE_STRICT.value,
invalid_input_error_code)

if 'id' not in request.data:
raise SkyflowError(SkyflowMessages.Error.IDS_KEY_ERROR.value, invalid_input_error_code)

def validate_detokenize_request(logger, request):
if not isinstance(request.redaction_type, RedactionType):
raise SkyflowError(SkyflowMessages.Error.INVALID_REDACTION_TYPE.value.format(type(request.redaction_type)), invalid_input_error_code)
Expand Down
4 changes: 2 additions & 2 deletions skyflow/vault/controller/_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def update(self, request: UpdateRequest):
validate_update_request(self.__vault_client.get_logger(), request)
log_info(SkyflowMessages.Info.UPDATE_REQUEST_RESOLVED.value, self.__vault_client.get_logger())
self.__initialize()
field = {key: value for key, value in request.data.items() if key != "id"}
field = {key: value for key, value in request.data.items() if key != "skyflow_id"}
record = V1FieldRecords(fields=field, tokens = request.tokens)
payload = RecordServiceUpdateRecordBody(record=record, tokenization=request.return_tokens, byot=request.token_strict.value)

Expand All @@ -113,7 +113,7 @@ def update(self, request: UpdateRequest):
api_response = records_api.record_service_update_record(
self.__vault_client.get_vault_id(),
request.table,
request.data.get("id"),
request.data.get("skyflow_id"),
payload
)
log_info(SkyflowMessages.Info.UPDATE_SUCCESS.value, self.__vault_client.get_logger())
Expand Down
4 changes: 2 additions & 2 deletions tests/vault/controller/test__vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_update_successful(self, mock_parse_response, mock_validate):
# Mock request
request = UpdateRequest(
table=TABLE_NAME,
data={"id": "12345", "field": "new_value"},
data={"skyflow_id": "12345", "field": "new_value"},
tokens=None,
return_tokens=True,
token_strict=TokenStrict.DISABLE
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_update_successful(self, mock_parse_response, mock_validate):
records_api.record_service_update_record.assert_called_once_with(
VAULT_ID,
request.table,
request.data["id"],
request.data["skyflow_id"],
expected_payload
)
mock_parse_response.assert_called_once_with(mock_api_response)
Expand Down

0 comments on commit a8a38f3

Please sign in to comment.