diff --git a/src/main/client/type.c b/src/main/client/type.c index 752df5e12..bea8f279f 100644 --- a/src/main/client/type.c +++ b/src/main/client/type.c @@ -1060,7 +1060,6 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args, self->as = aerospike_new(&config); if (AerospikeClientConnect(self) == -1) { - aerospike_destroy(self->as); return -1; } @@ -1368,6 +1367,6 @@ AerospikeClient *AerospikeClient_New(PyObject *parent, PyObject *args, raise_exception(&err); CLEANUP: - AerospikeClient_Type.tp_free(self); + AerospikeClient_Type.tp_dealloc((PyObject *)self); return NULL; } diff --git a/test/new_tests/test_new_constructor.py b/test/new_tests/test_new_constructor.py index 1d8236fee..a50d45847 100644 --- a/test/new_tests/test_new_constructor.py +++ b/test/new_tests/test_new_constructor.py @@ -8,6 +8,7 @@ from aerospike_helpers.batch.records import Write, BatchRecords from .test_scan_execute_background import wait_for_job_completion import copy +from contextlib import nullcontext gconfig = {} gconfig = TestBaseClass.get_connection_config() @@ -385,3 +386,23 @@ def test_invalid_read_touch_ttl_percent(self, policy_name: str): with pytest.raises(e.ParamError) as excinfo: aerospike.client(config) assert excinfo.value.msg == "Invalid Policy setting value" + + @pytest.mark.parametrize( + "config, context", + [ + ( + gconfig, + nullcontext() + ), + ( + { + "hosts": [("invalid-host", 4000)] + }, + # Tests that fail to connect should expect any of these exceptions + pytest.raises((e.ConnectionError, e.TimeoutError, e.ClientError)) + ) + ] + ) + def test_client_class_constructor(self, config: dict, context): + with context: + aerospike.Client(config)