Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
internal: more careful crud response process
In most cases, crud API response process assumes that there are
always two response values, which is rather uncommon. The reason of that
is internal crud wrappers [1]. This patch reworks response process a bit
to more carefully process this unusual case and to not confuse
developers.

1. https://github.com/tarantool/crud/blob/53457477974fed42351cbd87f566d11e9f7e39bb/crud/common/schema.lua#L88
  • Loading branch information
DifferentialOrange committed Sep 19, 2023
commit aed9b0ac8f8692a5e04b976aa8c6dd54ec767f82
51 changes: 23 additions & 28 deletions tarantool/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ def crud_insert(self, space_name: str, values: Union[tuple, list],

crud_resp = call_crud(self, "crud.insert", space_name, values, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2192,7 +2192,7 @@ def crud_insert_object(self, space_name: str, values: dict,

crud_resp = call_crud(self, "crud.insert_object", space_name, values, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2230,7 +2230,7 @@ def crud_insert_many(self, space_name: str, values: Union[tuple, list],
if crud_resp[0] is not None:
res = CrudResult(crud_resp[0])

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
errs = []
for err in crud_resp[1]:
errs.append(CrudError(err))
Expand Down Expand Up @@ -2271,7 +2271,7 @@ def crud_insert_object_many(self, space_name: str, values: Union[tuple, list],
if crud_resp[0] is not None:
res = CrudResult(crud_resp[0])

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
errs = []
for err in crud_resp[1]:
errs.append(CrudError(err))
Expand Down Expand Up @@ -2306,7 +2306,7 @@ def crud_get(self, space_name: str, key: int, opts: Optional[dict] = None) -> Cr

crud_resp = call_crud(self, "crud.get", space_name, key, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2345,7 +2345,7 @@ def crud_update(self, space_name: str, key: int, operations: Optional[list] = No

crud_resp = call_crud(self, "crud.update", space_name, key, operations, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2377,7 +2377,7 @@ def crud_delete(self, space_name: str, key: int, opts: Optional[dict] = None) ->

crud_resp = call_crud(self, "crud.delete", space_name, key, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2411,7 +2411,7 @@ def crud_replace(self, space_name: str, values: Union[tuple, list],

crud_resp = call_crud(self, "crud.replace", space_name, values, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2445,7 +2445,7 @@ def crud_replace_object(self, space_name: str, values: dict,

crud_resp = call_crud(self, "crud.replace_object", space_name, values, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2483,7 +2483,7 @@ def crud_replace_many(self, space_name: str, values: Union[tuple, list],
if crud_resp[0] is not None:
res = CrudResult(crud_resp[0])

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
errs = []
for err in crud_resp[1]:
errs.append(CrudError(err))
Expand Down Expand Up @@ -2524,7 +2524,7 @@ def crud_replace_object_many(self, space_name: str, values: Union[tuple, list],
if crud_resp[0] is not None:
res = CrudResult(crud_resp[0])

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
errs = []
for err in crud_resp[1]:
errs.append(CrudError(err))
Expand Down Expand Up @@ -2567,7 +2567,7 @@ def crud_upsert(self, space_name: str, values: Union[tuple, list],

crud_resp = call_crud(self, "crud.upsert", space_name, values, operations, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2608,7 +2608,7 @@ def crud_upsert_object(self, space_name: str, values: dict,

crud_resp = call_crud(self, "crud.upsert_object", space_name, values, operations, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2646,7 +2646,7 @@ def crud_upsert_many(self, space_name: str, values_operation: Union[tuple, list]
if crud_resp[0] is not None:
res = CrudResult(crud_resp[0])

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
errs = []
for err in crud_resp[1]:
errs.append(CrudError(err))
Expand Down Expand Up @@ -2687,7 +2687,7 @@ def crud_upsert_object_many(self, space_name: str, values_operation: Union[tuple
if crud_resp[0] is not None:
res = CrudResult(crud_resp[0])

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
errs = []
for err in crud_resp[1]:
errs.append(CrudError(err))
Expand Down Expand Up @@ -2726,7 +2726,7 @@ def crud_select(self, space_name: str, conditions: Optional[list] = None,

crud_resp = call_crud(self, "crud.select", space_name, conditions, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2758,7 +2758,7 @@ def crud_min(self, space_name: str, index_name: str, opts: Optional[dict] = None

crud_resp = call_crud(self, "crud.min", space_name, index_name, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2790,7 +2790,7 @@ def crud_max(self, space_name: str, index_name: str, opts: Optional[dict] = None

crud_resp = call_crud(self, "crud.max", space_name, index_name, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return CrudResult(crud_resp[0])
Expand Down Expand Up @@ -2819,9 +2819,7 @@ def crud_truncate(self, space_name: str, opts: Optional[dict] = None) -> bool:

crud_resp = call_crud(self, "crud.truncate", space_name, opts)

# In absence of an error, crud does not give
# variable err as nil (as in most cases).
if len(crud_resp) != 1:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return crud_resp[0]
Expand Down Expand Up @@ -2850,9 +2848,7 @@ def crud_len(self, space_name: str, opts: Optional[dict] = None) -> int:

crud_resp = call_crud(self, "crud.len", space_name, opts)

# In absence of an error, crud does not give
# variable err as nil (as in most cases).
if len(crud_resp) != 1:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return crud_resp[0]
Expand All @@ -2877,9 +2873,7 @@ def crud_storage_info(self, opts: Optional[dict] = None) -> dict:

crud_resp = call_crud(self, "crud.storage_info", opts)

# In absence of an error, crud does not give
# variable err as nil (as in most cases).
if len(crud_resp) != 1:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return crud_resp[0]
Expand Down Expand Up @@ -2915,7 +2909,7 @@ def crud_count(self, space_name: str, conditions: Optional[list] = None,

crud_resp = call_crud(self, "crud.count", space_name, conditions, opts)

if crud_resp[1] is not None:
if len(crud_resp) > 1 and crud_resp[1] is not None:
raise CrudModuleError(None, CrudError(crud_resp[1]))

return crud_resp[0]
Expand All @@ -2938,6 +2932,7 @@ def crud_stats(self, space_name: str = None) -> CrudResult:

crud_resp = call_crud(self, "crud.stats", space_name)

# There are no errors in `crud.stats`.
res = None
if len(crud_resp.data[0]) > 0:
res = CrudResult(crud_resp.data[0])
Expand Down