diff --git a/src/main/policy.c b/src/main/policy.c index e0fd08259..745eaa35b 100644 --- a/src/main/policy.c +++ b/src/main/policy.c @@ -1148,7 +1148,22 @@ as_status pyobject_to_map_policy(as_error *err, PyObject *py_policy, } MAP_POLICY_SET_FIELD(map_write_mode); - as_map_policy_set(policy, map_order, map_write_mode); + + PyObject *py_persist_index = + PyDict_GetItemString(py_policy, "persist_index"); + bool persist_index; + if (!py_persist_index) { + // Default value if persist_index isn't set in policy + persist_index = false; + } + else if (!PyBool_Check(py_persist_index)) { + // persist_index value must be valid if it is set + return as_error_update(err, AEROSPIKE_ERR_PARAM, + "persist_index is not a boolean"); + } + + persist_index = (bool)PyObject_IsTrue(py_persist_index); + as_map_policy_set_all(policy, map_order, map_write_mode, persist_index); return err->code; } diff --git a/test/new_tests/test_map_operation_helpers.py b/test/new_tests/test_map_operation_helpers.py index 044d9e040..d7a3dd3f8 100644 --- a/test/new_tests/test_map_operation_helpers.py +++ b/test/new_tests/test_map_operation_helpers.py @@ -79,11 +79,27 @@ def test_map_set_policy(self): """ Test setting map policy with an operation """ - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY, "map_order": aerospike.MAP_KEY_VALUE_ORDERED} + map_policy = { + "map_write_mode": aerospike.MAP_CREATE_ONLY, + "map_order": aerospike.MAP_KEY_VALUE_ORDERED, + "persist_index": True + } operations = [map_ops.map_set_policy(self.test_bin, map_policy)] self.as_connection.operate(self.test_key, operations) + def test_map_policy_invalid_persist_index(self): + map_policy = { + "persist_index": 1 + } + operations = [map_ops.map_set_policy(self.test_bin, map_policy)] + + with pytest.raises(e.ParamError): + self.as_connection.operate(self.test_key, operations) + + # Default persist index value should be tested automatically + # from other tests that don't set the persist index option + def test_map_put(self): operations = [map_ops.map_put(self.test_bin, "new", "map_put")] self.as_connection.operate(self.test_key, operations)