diff --git a/aerospike_helpers/batch/records.py b/aerospike_helpers/batch/records.py index 99e9f5816e..7de31879c9 100644 --- a/aerospike_helpers/batch/records.py +++ b/aerospike_helpers/batch/records.py @@ -60,6 +60,8 @@ def __init__(self, key: tuple) -> None: class Write(BatchRecord): """ Write is used for executing Batch write commands with batch_write and retrieving batch write results. + .. include:: ./deprecate_meta.rst + Attributes: key (:obj:`tuple`): The aerospike key to send the command to. record (:obj:`tuple`): The record corresponding to the requested key. @@ -111,6 +113,8 @@ def __init__( class Read(BatchRecord): """ Read is used for executing Batch read commands with batch_write and retrieving results. + .. include:: ./deprecate_meta.rst + Attributes: key (:obj:`tuple`): The aerospike key to send the command to. record (:obj:`tuple`): The record corresponding to the requested key. diff --git a/aerospike_helpers/operations/operations.py b/aerospike_helpers/operations/operations.py index eda976d78c..ff10701bbd 100644 --- a/aerospike_helpers/operations/operations.py +++ b/aerospike_helpers/operations/operations.py @@ -119,18 +119,18 @@ def increment(bin_name, amount): def touch(ttl: Optional[int] = None): """Create a touch operation dictionary. - Using ttl here is deprecated. It should be set in the record metadata for the operate method. + Using ttl here is deprecated. It should be set in the policy parameter for the operate method. Args: ttl (int): Deprecated. The ttl that should be set for the record. - This should be set in the metadata passed to the operate or + This should be set in the policy parameter passed to the operate or operate_ordered methods. Returns: A dictionary to be passed to operate or operate_ordered. """ op_dict = {"op": aerospike.OPERATOR_TOUCH} if ttl: - warnings.warn("TTL should be specified in the meta dictionary for operate", DeprecationWarning) + warnings.warn("TTL should be specified in the policy parameter for operate", DeprecationWarning) op_dict["val"] = ttl return op_dict diff --git a/doc/client.rst b/doc/client.rst index 5593f14f75..ffbdf132a6 100755 --- a/doc/client.rst +++ b/doc/client.rst @@ -100,6 +100,8 @@ Record Commands Create a new record, or remove / add bins to a record. + .. include:: ./deprecate_meta.rst + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param dict bins: contains bin name-value pairs of the record. :param dict meta: record metadata to be set. see :ref:`metadata_dict`. @@ -181,6 +183,8 @@ Record Commands (In Aerospike server versions prior to 3.6.0, non-existent bins being read will have a \ :py:obj:`None` value. ) + .. include:: ./deprecate_meta.rst + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param list list: See :ref:`aerospike_operation_helpers.operations`. :param dict meta: record metadata to be set. See :ref:`metadata_dict`. @@ -207,6 +211,8 @@ Record Commands Write operations or read operations that fail will not return a ``(bin-name, result)`` tuple. + .. include:: ./deprecate_meta.rst + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param list list: See :ref:`aerospike_operation_helpers.operations`. :param dict meta: record metadata to be set. See :ref:`metadata_dict`. @@ -224,6 +230,8 @@ Record Commands Touch the given record, setting its time-to-live and incrementing its generation. + .. include:: ./deprecate_meta.rst + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param int val: ttl in seconds, with ``0`` resolving to the default value in the server config. :param dict meta: record metadata to be set. see :ref:`metadata_dict` @@ -238,6 +246,8 @@ Record Commands Remove a record matching the *key* from the cluster. + .. include:: ./deprecate_meta.rst + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param dict meta: contains the expected generation of the record in a key called ``"gen"``. :param dict policy: see :ref:`aerospike_remove_policies`. May be passed as a keyword argument. @@ -252,6 +262,8 @@ Record Commands Remove a list of bins from a record with a given *key*. Equivalent to \ setting those bins to :meth:`aerospike.null` with a :meth:`~aerospike.put`. + .. include:: ./deprecate_meta.rst + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param list list: the bins names to be removed from the record. :param dict meta: record metadata to be set. See :ref:`metadata_dict`. @@ -408,6 +420,8 @@ String Operations Append a string to the string value in bin. + .. include:: ./deprecate_meta.rst + :param tuple key: a :ref:`aerospike_key_tuple` tuple associated with the record. :param str bin: the name of the bin. :param str val: the string to append to the bin value. @@ -427,6 +441,8 @@ String Operations Prepend the string value in *bin* with the string *val*. + .. include:: ./deprecate_meta.rst + :param tuple key: a :ref:`aerospike_key_tuple` tuple associated with the record. :param str bin: the name of the bin. :param str val: the string to prepend to the bin value. @@ -456,6 +472,8 @@ Numeric Operations Increment the integer value in *bin* by the integer *val*. + .. include:: ./deprecate_meta.rst + :param tuple key: a :ref:`aerospike_key_tuple` tuple associated with the record. :param str bin: the name of the bin. :param int offset: the value by which to increment the value in *bin*. diff --git a/doc/deprecate_meta.rst b/doc/deprecate_meta.rst new file mode 100644 index 0000000000..e721c10750 --- /dev/null +++ b/doc/deprecate_meta.rst @@ -0,0 +1,3 @@ +.. versionchanged:: 18.1.0 + + Deprecated the ``meta`` parameter. Use the policy parameter to set ``ttl`` and ``gen`` instead. diff --git a/src/include/client.h b/src/include/client.h index 4ba9447916..f66860ffbf 100644 --- a/src/include/client.h +++ b/src/include/client.h @@ -25,6 +25,10 @@ #define CLUSTER_NPARTITIONS (4096) +#define DEPRECATE_META_PARAMETER_WARNING_MESSAGE \ + "meta parameter is deprecated and will be removed in the " \ + "next client major release" + /******************************************************************************* * Macros for UDF operations. ******************************************************************************/ diff --git a/src/main/client/operate.c b/src/main/client/operate.c index 2910558c8a..352957cce1 100644 --- a/src/main/client/operate.c +++ b/src/main/client/operate.c @@ -926,6 +926,11 @@ static PyObject *AerospikeClient_Operate_Invoke(AerospikeClient *self, as_exp exp_list; as_exp *exp_list_p = NULL; + if (py_meta) { + PyErr_WarnEx(PyExc_DeprecationWarning, + DEPRECATE_META_PARAMETER_WARNING_MESSAGE, 2); + } + as_vector *unicodeStrVector = as_vector_create(sizeof(char *), 128); as_operations ops; @@ -1264,6 +1269,11 @@ PyObject *AerospikeClient_OperateOrdered(AerospikeClient *self, PyObject *args, return NULL; } + if (py_meta) { + PyErr_WarnEx(PyExc_DeprecationWarning, + DEPRECATE_META_PARAMETER_WARNING_MESSAGE, 2); + } + CHECK_CONNECTED(&err); if (pyobject_to_key(&err, py_key, &key) != AEROSPIKE_OK) { diff --git a/src/main/client/put.c b/src/main/client/put.c index 4822b0d670..9b139ae360 100644 --- a/src/main/client/put.c +++ b/src/main/client/put.c @@ -168,6 +168,11 @@ PyObject *AerospikeClient_Put(AerospikeClient *self, PyObject *args, return NULL; } + if (py_meta) { + PyErr_WarnEx(PyExc_DeprecationWarning, + DEPRECATE_META_PARAMETER_WARNING_MESSAGE, 2); + } + if (py_serializer_option) { if (PyLong_Check(py_serializer_option)) { self->is_client_put_serializer = true; diff --git a/src/main/client/remove.c b/src/main/client/remove.c index 0b76b6b358..1ead859625 100644 --- a/src/main/client/remove.c +++ b/src/main/client/remove.c @@ -170,6 +170,11 @@ PyObject *AerospikeClient_Remove(AerospikeClient *self, PyObject *args, return NULL; } + if (py_meta) { + PyErr_WarnEx(PyExc_DeprecationWarning, + DEPRECATE_META_PARAMETER_WARNING_MESSAGE, 2); + } + // Invoke Operation return AerospikeClient_Remove_Invoke(self, py_key, py_meta, py_policy); } diff --git a/src/main/client/remove_bin.c b/src/main/client/remove_bin.c index 0451d534b2..0c72bfbbf0 100644 --- a/src/main/client/remove_bin.c +++ b/src/main/client/remove_bin.c @@ -168,6 +168,11 @@ PyObject *AerospikeClient_RemoveBin(AerospikeClient *self, PyObject *args, return NULL; } + if (py_meta) { + PyErr_WarnEx(PyExc_DeprecationWarning, + DEPRECATE_META_PARAMETER_WARNING_MESSAGE, 2); + } + if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; diff --git a/test/new_tests/test_append.py b/test/new_tests/test_append.py index bf0a4cbbef..f5082da5d4 100644 --- a/test/new_tests/test_append.py +++ b/test/new_tests/test_append.py @@ -4,6 +4,7 @@ from aerospike import exception as e import aerospike +import warnings # @pytest.mark.usefixtures("as_connection") @@ -116,7 +117,11 @@ def test_pos_append_with_policy_key_gen_EQ_ignore(self): } meta = {"gen": 10, "ttl": 1200} - self.as_connection.append(key, "name", "str", meta, policy) + with warnings.catch_warnings(record=True) as warning_list: + self.as_connection.append(key, "name", "str", meta, policy) + + assert len(warning_list) == 1 + assert warning_list[0].category == DeprecationWarning (key, meta, bins) = self.as_connection.get(key) diff --git a/test/new_tests/test_new_constructor.py b/test/new_tests/test_client_config_level_options.py similarity index 99% rename from test/new_tests/test_new_constructor.py rename to test/new_tests/test_client_config_level_options.py index d9233c5b1e..9059b23e8d 100644 --- a/test/new_tests/test_new_constructor.py +++ b/test/new_tests/test_client_config_level_options.py @@ -280,7 +280,6 @@ def test_query_invalid_expected_duration(): # Some of these options may not be documented, but they are allowed in the code and customers may be using them def test_config_level_misc_options(): config = copy.deepcopy(gconfig) - config["policies"]["socket_timeout"] = 1 config["policies"]["total_timeout"] = 1 config["policies"]["max_retries"] = 1 config["policies"]["exists"] = aerospike.POLICY_EXISTS_CREATE @@ -322,6 +321,8 @@ def test_config_level_misc_options(): # We just make sure that the above options are allowed as dict keys try: aerospike.client(config) + except e.ParamError as exc: + raise exc except: pass diff --git a/test/new_tests/test_get_put.py b/test/new_tests/test_get_put.py index 628078a5bd..74c000d538 100644 --- a/test/new_tests/test_get_put.py +++ b/test/new_tests/test_get_put.py @@ -14,6 +14,7 @@ import aerospike from aerospike import exception as e +import warnings @contextmanager @@ -262,7 +263,11 @@ def test_pos_put_with_policy_exists_create_or_replace(self): "gen": aerospike.POLICY_GEN_IGNORE, "key": aerospike.POLICY_KEY_SEND, } - assert 0 == self.as_connection.put(key, rec, meta, policy) + + with warnings.catch_warnings(record=True) as warning_list: + assert 0 == self.as_connection.put(key, rec, meta, policy) + assert len(warning_list) == 1 + assert warning_list[0].category == DeprecationWarning (key, meta, bins) = self.as_connection.get(key) assert rec == bins diff --git a/test/new_tests/test_increment.py b/test/new_tests/test_increment.py index 1f6e71acae..9ad084c827 100644 --- a/test/new_tests/test_increment.py +++ b/test/new_tests/test_increment.py @@ -7,6 +7,7 @@ from aerospike import exception as e import aerospike +import warnings class TestIncrement(object): @@ -127,7 +128,11 @@ def test_increment_with_policy_key_gen_EQ_ignore(self): } meta = {"gen": 10, "ttl": 1200} - self.as_connection.increment(key, "age", 5, meta, policy) + with warnings.catch_warnings(record=True) as warning_list: + self.as_connection.increment(key, "age", 5, meta, policy) + + assert len(warning_list) == 1 + assert warning_list[0].category == DeprecationWarning (key, meta, bins) = self.as_connection.get(key) diff --git a/test/new_tests/test_operate.py b/test/new_tests/test_operate.py index 3c5a9550b8..ce4406bd52 100644 --- a/test/new_tests/test_operate.py +++ b/test/new_tests/test_operate.py @@ -4,6 +4,7 @@ import aerospike from aerospike import exception as e +import warnings # OPERATIONS # aerospike.OPERATOR_WRITE @@ -297,7 +298,10 @@ def test_pos_operate_with_policy_gen_ignore(self, key, policy, meta, llist): Invoke operate() with gen ignore. """ - key, meta, bins = self.as_connection.operate(key, llist, meta, policy) + with warnings.catch_warnings(record=True) as warning_list: + key, meta, bins = self.as_connection.operate(key, llist, meta, policy) + assert len(warning_list) == 1 + assert warning_list[0].category == DeprecationWarning assert bins == {"name": "name1aa"} assert key == ( diff --git a/test/new_tests/test_operate_ordered.py b/test/new_tests/test_operate_ordered.py index 67a10299b0..f940965a0c 100644 --- a/test/new_tests/test_operate_ordered.py +++ b/test/new_tests/test_operate_ordered.py @@ -5,6 +5,7 @@ import aerospike from aerospike import exception as e from aerospike_helpers.operations import operations +import warnings class TestOperateOrdered(object): @@ -222,7 +223,10 @@ def test_pos_operate_ordered_policy_gen_ignore(self, key, policy, meta, llist): """ Invoke operate_ordered() with gen ignore. """ - key, meta, bins = self.as_connection.operate_ordered(key, llist, meta, policy) + with warnings.catch_warnings(record=True) as warning_list: + key, meta, bins = self.as_connection.operate_ordered(key, llist, meta, policy) + assert len(warning_list) == 1 + assert warning_list[0].category == DeprecationWarning assert bins == [("name", "name1aa")] diff --git a/test/new_tests/test_prepend.py b/test/new_tests/test_prepend.py index e6bfb08e9a..e5b67bd8e1 100644 --- a/test/new_tests/test_prepend.py +++ b/test/new_tests/test_prepend.py @@ -4,6 +4,7 @@ from .test_base_class import TestBaseClass import aerospike from aerospike import exception as e +import warnings class TestPrepend: @@ -101,7 +102,10 @@ def test_pos_prepend_with_policy_key_gen_EQ_ignore(self): } meta = {"gen": 10, "ttl": 1200} - self.as_connection.prepend(key, "name", "str", meta, policy) + with warnings.catch_warnings(record=True) as warning_list: + self.as_connection.prepend(key, "name", "str", meta, policy) + assert len(warning_list) == 1 + assert warning_list[0].category == DeprecationWarning (key, meta, bins) = self.as_connection.get(key) diff --git a/test/new_tests/test_remove.py b/test/new_tests/test_remove.py index c0ed09126e..55643433f1 100644 --- a/test/new_tests/test_remove.py +++ b/test/new_tests/test_remove.py @@ -6,6 +6,7 @@ from .test_base_class import TestBaseClass import aerospike from aerospike import exception as e +import warnings @pytest.mark.usefixtures("as_connection")