Skip to content

Commit

Permalink
Merge pull request #92 from skyflowapi/release/23.7.2-patch
Browse files Browse the repository at this point in the history
SK-865 Release/23.7.2 patch
  • Loading branch information
skyflow-bharti authored Jul 28, 2023
2 parents ee8a462 + 76fce8e commit 4bea819
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def token_provider():
}
]}

response = client.delete_by_id(data,options=options)
response = client.delete(data,options=options)
print('Response:', response)
except SkyflowError as e:
print('Error Occurred:', e)
4 changes: 2 additions & 2 deletions skyflow/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class InfoMessages(Enum):
UPDATE_DATA_SUCCESS = "Data has been updated successfully"
GET_TRIGGERED = "Get triggered."
GET_SUCCESS = "Data fetched successfully."
DELETE_BY_ID_TRIGGERED = "Delete by ID triggered."
DELETE_TRIGGERED = "Delete triggered."
DELETE_DATA_SUCCESS = "Data has been deleted successfully."


Expand All @@ -91,7 +91,7 @@ class InterfaceName(Enum):

IS_TOKEN_VALID = "service_account.isTokenValid"
IS_EXPIRED = "service_account.is_expired"
DELETE_BY_ID = "client.delete_by_id"
DELETE = "client.delete"


def http_build_query(data):
Expand Down
5 changes: 2 additions & 3 deletions skyflow/errors/_skyflow_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ class SkyflowErrorMessages(Enum):
INVALID_REDACTION_TYPE = "Redaction key has value of type %s, expected Skyflow.Redaction"
INVALID_COLUMN_NAME = "Column name has value of type %s, expected string"
INVALID_COLUMN_VALUE = "Column values has value of type %s, expected list"
INVALID_RECORDS_IN_DELETE = "Invalid records. records object should be an array"
EMPTY_RECORDS_IN_DELETE = "records array cannot be empty"
EMPTY_ID_IN_DELETE = "Id cannot be empty in records array at index %s"
EMPTY_TABLE_IN_DELETE = "Table cannot be empty in records array at index %s"
EMPTY_ID_IN_DELETE = "Id cannot be empty in records array"
EMPTY_TABLE_IN_DELETE = "Table cannot be empty in records array"
RECORDS_KEY_NOT_FOUND_DELETE = "records object is required"

INVALID_REQUEST_BODY = "Given request body is not valid"
Expand Down
94 changes: 47 additions & 47 deletions skyflow/vault/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import types
import requests

from ._delete_by_id import deleteProcessResponse
from ._delete import deleteProcessResponse
from ._insert import getInsertRequestBody, processResponse, convertResponse
from ._update import sendUpdateRequests, createUpdateResponseBody
from ._config import Configuration, DeleteOptions
Expand Down Expand Up @@ -176,9 +176,9 @@ def update(self, updateInput, options: UpdateOptions = UpdateOptions()):
log_info(InfoMessages.UPDATE_DATA_SUCCESS.value, interface)
return result

def delete_by_id(self, records: dict,options: DeleteOptions = DeleteOptions()):
interface = InterfaceName.DELETE_BY_ID.value
log_info(InfoMessages.DELETE_BY_ID_TRIGGERED.value, interface=interface)
def delete(self, records: dict, options: DeleteOptions = DeleteOptions()):
interface = InterfaceName.DELETE.value
log_info(InfoMessages.DELETE_TRIGGERED.value, interface=interface)

self._checkConfig(interface)

Expand All @@ -192,58 +192,53 @@ def delete_by_id(self, records: dict,options: DeleteOptions = DeleteOptions()):
result_list = []
errors = {}
result = {}
error = {}
try:
if not isinstance(records, dict) or "records" not in records:
error = {"error": {"code": SkyflowErrorCodes.INVALID_INPUT.value,
"description": SkyflowErrorMessages.RECORDS_KEY_NOT_FOUND_DELETE.value}}
return error
records_list = records["records"]
if not isinstance(records_list, list):
error.update({"error": {"code": SkyflowErrorCodes.INVALID_INPUT.value,
"description": SkyflowErrorMessages.INVALID_RECORDS_IN_DELETE.value}})
return error
elif len(records_list) == 0:
error = {"error": {"code": SkyflowErrorCodes.INVALID_INPUT.value,
"description": SkyflowErrorMessages.EMPTY_RECORDS_IN_DELETE.value}}
return error
record = records["records"]
if not isinstance(record, list):
recordsType = str(type(record))
raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT, SkyflowErrorMessages.INVALID_RECORDS_TYPE.value % (
recordsType), interface=interface)
if len(record) == 0:
raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT,
SkyflowErrorMessages.EMPTY_RECORDS_IN_DELETE, interface=interface)

except KeyError:
raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT,
SkyflowErrorMessages.RECORDS_KEY_ERROR, interface=interface)
try:
for index,record in enumerate(records["records"]):
record_list = record["id"]
if not isinstance(record_list, str):
error.update({"error": {"code": SkyflowErrorCodes.INVALID_INDEX.value,
"description": SkyflowErrorMessages.INVALID_ID_TYPE_DELETE.value % (index)}})
return error
elif record_list == "":
error.update({"error": {"code": SkyflowErrorCodes.INVALID_INPUT.value,
"description": SkyflowErrorMessages.EMPTY_ID_IN_DELETE.value % (index)}})
return error
for record in records["records"]:
id = record["id"]
if not isinstance(id, str):
idType = str(type(id))
raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT,
SkyflowErrorMessages.INVALID_ID_TYPE.value % (idType), interface=interface)
if id == "":
raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT,
SkyflowErrorMessages.EMPTY_ID_IN_DELETE, interface=interface)
except KeyError:
error.update({"error": {"code": SkyflowErrorCodes.INVALID_INDEX.value,
"description": SkyflowErrorMessages.IDS_KEY_ERROR.value}})
return error
raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT,
SkyflowErrorMessages.IDS_KEY_ERROR, interface=interface)
try:
for index,record in enumerate(records["records"]):
record_table = record["table"]
if not isinstance(record_table, str):
error.update({"error": {"code": SkyflowErrorCodes.INVALID_INPUT.value,
"description": SkyflowErrorMessages.INVALID_TABLE_TYPE_DELETE.value % (index)}})
return error
elif record_table == "":
error.update({"error": {"code": SkyflowErrorCodes.INVALID_INPUT.value,
"description": SkyflowErrorMessages.EMPTY_TABLE_IN_DELETE.value % (index)}})
return error
for record in records["records"]:
table = record["table"]
if not isinstance(table, str):
tableType = str(type(table))
raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT,
SkyflowErrorMessages.INVALID_TABLE_TYPE.value % (
tableType), interface=interface)
if table == "":
raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT,
SkyflowErrorMessages.EMPTY_TABLE_IN_DELETE, interface=interface)
except KeyError:
error.update({"error": {"code": SkyflowErrorCodes.INVALID_INDEX.value,
"description": SkyflowErrorMessages.TABLE_KEY_ERROR.value}})
return error
raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT,
SkyflowErrorMessages.TABLE_KEY_ERROR, interface=interface)

partial=None

for record in records["records"]:
request_url = self._get_complete_vault_url() + "/" + record["table"] + "/" + record["id"]
response = requests.delete(request_url, headers=headers)
processed_response = deleteProcessResponse(response, records)
partial,processed_response = deleteProcessResponse(response, records)
if processed_response is not None and processed_response.get('code') == 404:
errors.update({'id': record["id"], 'error': processed_response})
error_list.append(errors)
Expand All @@ -254,5 +249,10 @@ def delete_by_id(self, records: dict,options: DeleteOptions = DeleteOptions()):
if errors:
result.update({'errors': error_list})

log_info(InfoMessages.DELETE_DATA_SUCCESS.value, interface)
return result
if partial:
raise SkyflowError(SkyflowErrorCodes.PARTIAL_SUCCESS,
SkyflowErrorMessages.PARTIAL_SUCCESS, result, interface=interface)

else:
log_info(InfoMessages.DELETE_DATA_SUCCESS.value, interface)
return result
8 changes: 5 additions & 3 deletions skyflow/vault/_delete_by_id.py → skyflow/vault/_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
from skyflow.errors._skyflow_errors import SkyflowError, SkyflowErrorCodes, SkyflowErrorMessages
from skyflow._utils import InterfaceName

interface = InterfaceName.DELETE_BY_ID.value
interface = InterfaceName.DELETE.value


def deleteProcessResponse(response: requests.Response, interface=interface):
statusCode = response.status_code
content = response.content
partial = False
try:
response.raise_for_status()
if statusCode == 204:
return None
try:
return json.loads(content)
return partial,json.loads(content)
except:
raise SkyflowError(
statusCode, SkyflowErrorMessages.RESPONSE_NOT_JSON.value % content, interface=interface)
Expand All @@ -31,11 +32,12 @@ def deleteProcessResponse(response: requests.Response, interface=interface):
if 'error' in errorResponse and type(errorResponse['error']) == dict and 'message' in errorResponse[
'error']:
message = errorResponse['error']['message']
partial=True
except:
message = SkyflowErrorMessages.RESPONSE_NOT_JSON.value % content
error = {}
if 'x-request-id' in response.headers:
message += ' - request id: ' + response.headers['x-request-id']
error.update({"code": statusCode, "description": message})
return error
return partial,error

Loading

0 comments on commit 4bea819

Please sign in to comment.