diff --git a/src/main/client/truncate.c b/src/main/client/truncate.c index 8af0d7149..486e48636 100644 --- a/src/main/client/truncate.c +++ b/src/main/client/truncate.c @@ -82,6 +82,16 @@ PyObject *AerospikeClient_Truncate(AerospikeClient *self, PyObject *args, return NULL; } + if (!self || !self->as) { + as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); + goto CLEANUP; + } + if (!self->is_conn_16) { + as_error_update(&err, AEROSPIKE_ERR_CLUSTER, + "No connection to aerospike cluster"); + goto CLEANUP; + } + // Start conversion of the namespace parameter if (PyUnicode_Check(py_ns)) { namespace = strdup((char *)PyUnicode_AsUTF8(py_ns)); diff --git a/test/new_tests/test_truncate.py b/test/new_tests/test_truncate.py index 335b6e648..1e46b355b 100644 --- a/test/new_tests/test_truncate.py +++ b/test/new_tests/test_truncate.py @@ -203,3 +203,8 @@ def test_whole_set_truncation_with_invalid_policy(self): def test_whole_set_truncation_with_invalid_policy_type(self, policy): with pytest.raises(e.ClientError): self.as_connection.truncate("test", "truncate", 0, policy) + + def test_truncate_after_close(self): + self.as_connection.close() + with pytest.raises(e.ClusterError): + self.as_connection.truncate("test", None, 0)