Skip to content

Commit

Permalink
Prevent further regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannguyen4 committed Feb 27, 2024
1 parent c779a3b commit 8465fc2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
26 changes: 4 additions & 22 deletions src/main/client/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ enum {
INIT_CONFIG_TYPE_ERR,
INIT_LUA_USER_ERR,
INIT_LUA_SYS_ERR,
INIT_HOSTS_NOT_FOUND_ERR,
INIT_HOST_TYPE_ERR,
INIT_EMPTY_HOSTS_ERR,
INIT_INVALID_ADRR_ERR,
INIT_SERIALIZE_ERR,
Expand Down Expand Up @@ -645,14 +645,7 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args,
}

PyObject *py_hosts = PyDict_GetItemString(py_config, "hosts");
if (py_hosts) {
if (!PyList_Check(py_hosts)) {
initialize_config_value_type_err(config_value_type_error_msg,
"[\"hosts\"]", "list",
&error_code);
goto CONSTRUCTOR_ERROR;
}

if (py_hosts && PyList_Check(py_hosts)) {
int size = (int)PyList_Size(py_hosts);
if (!size) {
error_code = INIT_EMPTY_HOSTS_ERR;
Expand Down Expand Up @@ -724,17 +717,6 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args,
port = (uint16_t)atoi(temp);
}
}
else {
// ["hosts"][<10 chars max>]
// 1234567890123456789012345
// 0 10 20 + 1 = 26
char keys_str[26];
snprintf(keys_str, 26, "[\"hosts\"][%d]", i);
initialize_config_value_type_err(config_value_type_error_msg,
keys_str, "tuple",
&error_code);
goto CONSTRUCTOR_ERROR;
}

if (addr) {
if (tls_name) {
Expand All @@ -753,7 +735,7 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args,
}
}
else {
error_code = INIT_HOSTS_NOT_FOUND_ERR;
error_code = INIT_HOST_TYPE_ERR;
goto CONSTRUCTOR_ERROR;
}

Expand Down Expand Up @@ -1346,7 +1328,7 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args,
"Lua system path too long");
break;
}
case INIT_HOSTS_NOT_FOUND_ERR: {
case INIT_HOST_TYPE_ERR: {
as_error_update(&constructor_err, AEROSPIKE_ERR_PARAM,
"Hosts must be a list");
break;
Expand Down
4 changes: 2 additions & 2 deletions test/new_tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def test_connect_with_extra_args(self):
[
(1, e.ParamError, -2, "Config must be a dict"),
({}, e.ParamError, -2, "Hosts must be a list"),
({"": [("127.0.0.1", 3000)]}, e.ParamError, -2, "\"hosts\" is a required key in the config dictionary"),
({"hosts": [3000]}, e.ParamError, -2, "config[\"hosts\"][0] must be a tuple"),
({"": [("127.0.0.1", 3000)]}, e.ParamError, -2, "Hosts must be a list"),
({"hosts": [3000]}, e.ParamError, -2, "Invalid host"),
# Errors that throw -10 can also throw 9
({"hosts": [("127.0.0.1", 2000)]}, (e.ClientError, e.TimeoutError), (-10, 9), "Failed to connect"),
({"hosts": [("127.0.0.1", "3000")]}, e.ClientError, -10, "Failed to connect"),
Expand Down

0 comments on commit 8465fc2

Please sign in to comment.