diff --git a/aerospike-stubs/aerospike.pyi b/aerospike-stubs/aerospike.pyi index 31edad6023..37ffc1c21a 100644 --- a/aerospike-stubs/aerospike.pyi +++ b/aerospike-stubs/aerospike.pyi @@ -478,7 +478,7 @@ class Client: def put(self, key: tuple, bins: dict, meta: dict = ..., policy: dict = ..., serializer = ...) -> None: ... def query(self, namespace: str, set: Optional[str] = None) -> Query: ... def query_apply(self, ns: str, set: str, predicate: tuple, module: str, function: str, args: list = ..., policy: dict = ...) -> int: ... - def remove(self, key: tuple, meta: dict = ..., policy: dict = ...) -> None: ... + def remove(self, key: tuple, policy: dict = ...) -> None: ... def remove_bin(self, key: tuple, list: list, meta: dict = ..., policy: dict = ...) -> None: ... def scan(self, namespace: str, set: Optional[str] = None) -> Scan: ... def scan_apply(self, ns: str, set: str, module: str, function: str, args: list = ..., policy: dict = ..., options: dict = ...) -> int: ... diff --git a/aerospike_helpers/batch/records.py b/aerospike_helpers/batch/records.py index 7afe9c1c42..55018dabdd 100644 --- a/aerospike_helpers/batch/records.py +++ b/aerospike_helpers/batch/records.py @@ -65,8 +65,6 @@ 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_ttl.rst - Attributes: key (:obj:`tuple`): The aerospike key to send the command to. record (:obj:`tuple`): The record corresponding to the requested key. @@ -76,7 +74,7 @@ class Write(BatchRecord): to the server. ops (:ref:`aerospike_operation_helpers.operations`): A list of aerospike operation dictionaries to perform on the record at key. - meta (dict): the metadata to set for this command + meta (dict): the expected generation for this record policy (:ref:`aerospike_batch_write_policies`, optional): An optional dictionary of batch write policy flags. """ @@ -120,9 +118,6 @@ def __init__( class Read(BatchRecord): """ Read is used for executing Batch read commands with batch_write and retrieving results. - .. deprecated:: 19.1.0 Deprecated the ``"ttl"`` option in the ``meta`` parameter. Use the policy parameter in a - :py:obj:`~aerospike_helpers.batch.records.Write` BatchRecord to set the ``"ttl"`` instead. - Attributes: key (:obj:`tuple`): The aerospike key to send the command to. record (:obj:`tuple`): The record corresponding to the requested key. @@ -132,7 +127,7 @@ class Read(BatchRecord): to the server. ops (:ref:`aerospike_operation_helpers.operations`): list of aerospike operation dictionaries to perform on the record at key. - meta (dict): the metadata to set for this command + meta (dict): the expected generation for this record read_all_bins (:obj:`bool`, optional): An optional bool, if True, read all bins in the record. policy (:ref:`aerospike_batch_read_policies`, optional): An optional dictionary of batch read policy flags. """ diff --git a/doc/client.rst b/doc/client.rst index 8aa43b1ba4..502894c7a6 100755 --- a/doc/client.rst +++ b/doc/client.rst @@ -152,11 +152,9 @@ Record Commands Create a new record, or remove / add bins to a record. - .. include:: ./deprecate_meta_ttl.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`. + :param dict meta: record generation to compare. see :ref:`metadata_dict`. :param dict policy: see :ref:`aerospike_write_policies`. :param serializer: override the serialization mode of the client \ @@ -317,11 +315,9 @@ 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_ttl.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`. + :param dict meta: record generation to compare. See :ref:`metadata_dict`. :param dict policy: optional :ref:`aerospike_operate_policies`. :return: a :ref:`aerospike_record_tuple`. :raises: a subclass of :exc:`~aerospike.exception.AerospikeError`. @@ -372,11 +368,9 @@ Record Commands Write operations or read operations that fail will not return a ``(bin-name, result)`` tuple. - .. include:: ./deprecate_meta_ttl.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`. + :param dict meta: record generation to compare. See :ref:`metadata_dict`. :param dict policy: optional :ref:`aerospike_operate_policies`. :return: a :ref:`aerospike_record_tuple`. @@ -414,13 +408,9 @@ Record Commands Touch the given record, setting its time-to-live and incrementing its generation. - .. versionchanged:: 19.1.0 - - Deprecated the ``meta["ttl"]`` parameter. Use the ``val`` parameter instead. - :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` + :param dict meta: record generation to compare. see :ref:`metadata_dict` :param dict policy: see :ref:`aerospike_operate_policies`. :raises: a subclass of :exc:`~aerospike.exception.AerospikeError`. @@ -446,16 +436,11 @@ Record Commands {'ttl': 2592000, 'gen': 1} {'ttl': 120, 'gen': 2} - .. method:: remove(key[meta: dict[, policy: dict]]) + .. method:: remove(key[, policy: dict]) Remove a record matching the *key* from the cluster. - .. versionchanged:: 19.1.0 - - Deprecated the ``meta`` parameter. Use the policy parameter to set ``gen`` instead. - :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. :raises: a subclass of :exc:`~aerospike.exception.AerospikeError`. @@ -468,7 +453,7 @@ Record Commands # Try to remove it with the wrong generation try: - client.remove(keyTuple, meta={'gen': 5}, policy={'gen': aerospike.POLICY_GEN_EQ}) + client.remove(keyTuple, policy={'gen': aerospike.POLICY_GEN_EQ, 'generation': 5}) except ex.AerospikeError as e: print("Error: {0} [{1}]".format(e.msg, e.code)) @@ -484,11 +469,9 @@ 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.Client.put`. - .. include:: ./deprecate_meta_ttl.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`. + :param dict meta: record generation to compare. See :ref:`metadata_dict`. :param dict policy: optional :ref:`aerospike_write_policies`. :raises: a subclass of :exc:`~aerospike.exception.AerospikeError`. @@ -817,12 +800,10 @@ String Operations Append a string to the string value in bin. - .. include:: ./deprecate_meta_ttl.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. - :param dict meta: record metadata to be set. See :ref:`metadata_dict`. + :param dict meta: record generation to compare. See :ref:`metadata_dict`. :param dict policy: optional :ref:`aerospike_operate_policies`. :raises: a subclass of :exc:`~aerospike.exception.AerospikeError`. @@ -844,12 +825,10 @@ String Operations Prepend the string value in *bin* with the string *val*. - .. include:: ./deprecate_meta_ttl.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. - :param dict meta: record metadata to be set. See :ref:`metadata_dict`. + :param dict meta: record generation to compare. See :ref:`metadata_dict`. :param dict policy: optional :ref:`aerospike_operate_policies`. :raises: a subclass of :exc:`~aerospike.exception.AerospikeError`. @@ -880,13 +859,11 @@ Numeric Operations Increment the integer value in *bin* by the integer *val*. - .. include:: ./deprecate_meta_ttl.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*. :type offset: :py:class:`int` or :py:class:`float` - :param dict meta: record metadata to be set. See :ref:`metadata_dict`. + :param dict meta: record generation to compare. See :ref:`metadata_dict`. :param dict policy: optional :ref:`aerospike_operate_policies`. Note: the ``exists`` policy option may not be: :py:data:`aerospike.POLICY_EXISTS_CREATE_OR_REPLACE` nor :py:data:`aerospike.POLICY_EXISTS_REPLACE` :raises: a subclass of :exc:`~aerospike.exception.AerospikeError`. @@ -2014,8 +1991,9 @@ Metadata Dictionary The metadata dictionary has the following key-value pairs: - * ``"ttl"`` (:class:`int`): record time to live in seconds. See :ref:`TTL_CONSTANTS` for possible special values. - * ``"gen"`` (:class:`int`): record generation + * ``"ttl"`` (:class:`int`): record time to live in seconds. This field is read only. + * ``"gen"`` (:class:`int`): record generation. If passing as input, this is the expected record generation. + If returned as an output, this is the current record generation. .. _aerospike_policies: diff --git a/doc/deprecate_meta_ttl.rst b/doc/deprecate_meta_ttl.rst deleted file mode 100644 index 907f1cb50c..0000000000 --- a/doc/deprecate_meta_ttl.rst +++ /dev/null @@ -1,3 +0,0 @@ -.. versionchanged:: 19.1.0 - - Deprecated the ``meta["ttl"]`` parameter. Use the policy parameter to set ``ttl`` instead. diff --git a/src/include/client.h b/src/include/client.h index 61699d18a9..2bdac57bbc 100644 --- a/src/include/client.h +++ b/src/include/client.h @@ -157,7 +157,7 @@ PyObject *AerospikeClient_Remove(AerospikeClient *self, PyObject *args, PyObject *kwds); PyObject *AerospikeClient_Remove_Invoke(AerospikeClient *self, PyObject *py_key, - PyObject *py_meta, PyObject *py_policy); + PyObject *py_policy); /** * Remove bin from the database. diff --git a/src/include/conversions.h b/src/include/conversions.h index c7efa5d55d..fe7381dadb 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -155,11 +155,10 @@ void initialize_bin_for_strictypes(AerospikeClient *self, as_error *err, PyObject *py_value, as_binop *binop, char *bin, as_static_pool *static_pool); -// Both as_operations and as_record have ttl and gen fields, -// so we have ttl and gen as separate parameters instead of accepting either as_operations or as_record -as_status check_and_set_meta(PyObject *py_meta, uint32_t *ttl_ref, - uint16_t *gen_ref, as_error *err, - bool validate_keys); +// Both as_operations and as_record have gen fields, +// so we have gen as a separate parameter instead of accepting either as_operations or as_record +as_status check_and_set_meta(PyObject *py_meta, uint16_t *gen_ref, + as_error *err, bool validate_keys); as_status string_and_pyuni_from_pystring(PyObject *py_string, PyObject **pyuni_r, char **c_str_ptr, diff --git a/src/main/aerospike.c b/src/main/aerospike.c index 794cfca9eb..0bb81eb13f 100644 --- a/src/main/aerospike.c +++ b/src/main/aerospike.c @@ -951,7 +951,7 @@ DEFINE_SET_OF_VALID_KEYS(hll_policy, "flags", NULL) DEFINE_SET_OF_VALID_KEYS(admin_policy, "timeout", NULL) -DEFINE_SET_OF_VALID_KEYS(record_metadata, "gen", "ttl", NULL) +DEFINE_SET_OF_VALID_KEYS(record_metadata, "gen", NULL) // Use a struct to create pairs of pyobjects and list of strings defined above // When we initialize the module, we create sets for the valid keys that the client can use later diff --git a/src/main/client/batch_write.c b/src/main/client/batch_write.c index f369b27402..cf1d4fcb86 100644 --- a/src/main/client/batch_write.c +++ b/src/main/client/batch_write.c @@ -297,8 +297,10 @@ static PyObject *AerospikeClient_BatchWriteInvoke(AerospikeClient *self, ops = as_operations_new(py_ops_size); garb->ops_to_free = ops; + // as_operations_new defaults ttl to 0 (namespace default). Use the batch write policy ttl instead. + ops->ttl = AS_RECORD_CLIENT_DEFAULT_TTL; - if (check_and_set_meta(py_meta, &ops->ttl, &ops->gen, err, + if (check_and_set_meta(py_meta, &ops->gen, err, self->validate_keys) != AEROSPIKE_OK) { goto CLEANUP_ON_ERROR; } diff --git a/src/main/client/operate.c b/src/main/client/operate.c index 831a1ef2fa..94860451cb 100644 --- a/src/main/client/operate.c +++ b/src/main/client/operate.c @@ -944,6 +944,8 @@ static PyObject *AerospikeClient_Operate_Invoke(AerospikeClient *self, as_operations ops; Py_ssize_t size = PyList_Size(py_list); as_operations_inita(&ops, size); + // as_operations_inita defaults ttl to 0 (namespace default). Use the operate policy ttl instead. + ops.ttl = AS_RECORD_CLIENT_DEFAULT_TTL; if (py_policy) { if (pyobject_to_policy_operate(self, err, py_policy, &operate_policy, @@ -958,8 +960,8 @@ static PyObject *AerospikeClient_Operate_Invoke(AerospikeClient *self, memset(&static_pool, 0, sizeof(static_pool)); CHECK_CONNECTED(err); - if (check_and_set_meta(py_meta, &ops.ttl, &ops.gen, err, - self->validate_keys) != AEROSPIKE_OK) { + if (check_and_set_meta(py_meta, &ops.gen, err, self->validate_keys) != + AEROSPIKE_OK) { goto CLEANUP; } @@ -1109,6 +1111,8 @@ AerospikeClient_OperateOrdered_Invoke(AerospikeClient *self, as_error *err, as_operations ops; Py_ssize_t ops_list_size = PyList_Size(py_list); as_operations_inita(&ops, ops_list_size); + // as_operations_inita defaults ttl to 0 (namespace default). Use the operate policy ttl instead. + ops.ttl = AS_RECORD_CLIENT_DEFAULT_TTL; // For expressions conversion. as_exp *exp_list_p = NULL; @@ -1129,8 +1133,8 @@ AerospikeClient_OperateOrdered_Invoke(AerospikeClient *self, as_error *err, } } - if (check_and_set_meta(py_meta, &ops.ttl, &ops.gen, err, - self->validate_keys) != AEROSPIKE_OK) { + if (check_and_set_meta(py_meta, &ops.gen, err, self->validate_keys) != + AEROSPIKE_OK) { goto CLEANUP; } diff --git a/src/main/client/remove.c b/src/main/client/remove.c index 345d3702a3..8f006df74f 100644 --- a/src/main/client/remove.c +++ b/src/main/client/remove.c @@ -41,7 +41,7 @@ ******************************************************************************************************* */ PyObject *AerospikeClient_Remove_Invoke(AerospikeClient *self, PyObject *py_key, - PyObject *py_meta, PyObject *py_policy) + PyObject *py_policy) { // Aerospike Client Arguments @@ -86,33 +86,6 @@ PyObject *AerospikeClient_Remove_Invoke(AerospikeClient *self, PyObject *py_key, if (err.code != AEROSPIKE_OK) { goto CLEANUP; } - else { - if (py_meta && PyDict_Check(py_meta)) { - PyObject *py_gen = PyDict_GetItemString(py_meta, "gen"); - - if (py_gen) { - if (PyLong_Check(py_gen)) { - remove_policy_p->generation = - (uint16_t)PyLong_AsLong(py_gen); - } - else if (PyLong_Check(py_gen)) { - remove_policy_p->generation = - (uint16_t)PyLong_AsLongLong(py_gen); - if ((uint16_t)-1 == remove_policy_p->generation && - PyErr_Occurred()) { - as_error_update( - &err, AEROSPIKE_ERR_PARAM, - "integer value for gen exceeds sys.maxsize"); - goto CLEANUP; - } - } - else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, - "Generation should be an int or long"); - } - } - } - } } // Invoke operation @@ -158,28 +131,16 @@ PyObject *AerospikeClient_Remove(AerospikeClient *self, PyObject *args, // Python Function Arguments PyObject *py_key = NULL; PyObject *py_policy = NULL; - PyObject *py_meta = NULL; // Python Function Keyword Arguments - static char *kwlist[] = {"key", "meta", "policy", NULL}; + static char *kwlist[] = {"key", "policy", NULL}; // Python Function Argument Parsing - if (PyArg_ParseTupleAndKeywords(args, kwds, "O|OO:remove", kwlist, &py_key, - &py_meta, &py_policy) == false) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "O|O:remove", kwlist, &py_key, + &py_policy) == false) { return NULL; } - if (py_meta) { - int retval = PyErr_WarnEx( - PyExc_DeprecationWarning, - "meta parameter is deprecated and will be removed in the " - "next client major release", - STACK_LEVEL); - if (retval == -1) { - return NULL; - } - } - // Invoke Operation - return AerospikeClient_Remove_Invoke(self, py_key, py_meta, py_policy); + return AerospikeClient_Remove_Invoke(self, py_key, py_policy); } diff --git a/src/main/client/remove_bin.c b/src/main/client/remove_bin.c index 06c376ddb6..21790beca5 100644 --- a/src/main/client/remove_bin.c +++ b/src/main/client/remove_bin.c @@ -98,6 +98,8 @@ AerospikeClient_RemoveBin_Invoke(AerospikeClient *self, PyObject *py_key, Py_ssize_t size = PyList_Size(py_binList); // Initialize record as_record_inita(&rec, size); + // as_record_inita defaults ttl to 0 (namespace default). Use the write policy ttl instead. + rec.ttl = AS_RECORD_CLIENT_DEFAULT_TTL; // Convert python key object to as_key pyobject_to_key(err, py_key, &key); @@ -142,7 +144,7 @@ AerospikeClient_RemoveBin_Invoke(AerospikeClient *self, PyObject *py_key, } } - check_and_set_meta(py_meta, &rec.ttl, &rec.gen, err, self->validate_keys); + check_and_set_meta(py_meta, &rec.gen, err, self->validate_keys); if (err->code != AEROSPIKE_OK) { goto CLEANUP; } diff --git a/src/main/conversions.c b/src/main/conversions.c index 69fdd9f8c2..d0beb6e346 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -1545,6 +1545,8 @@ as_status as_record_init_from_pyobject(AerospikeClient *self, as_error *err, const char *name; as_record_init(rec, size); + // as_record_init defaults ttl to 0 (namespace default). Use the write policy ttl instead. + rec->ttl = AS_RECORD_CLIENT_DEFAULT_TTL; while (PyDict_Next(py_bins_dict, &pos, &py_bin_name, &py_bin_value)) { if (!PyUnicode_Check(py_bin_name)) { @@ -1591,7 +1593,7 @@ as_status as_record_init_from_pyobject(AerospikeClient *self, as_error *err, } } - check_and_set_meta(py_meta, &rec->ttl, &rec->gen, err, self->validate_keys); + check_and_set_meta(py_meta, &rec->gen, err, self->validate_keys); CLEANUP: if (err->code != AEROSPIKE_OK) { @@ -2430,9 +2432,8 @@ void initialize_bin_for_strictypes(AerospikeClient *self, as_error *err, * Returns: error code. ******************************************************************************************************* */ -as_status check_and_set_meta(PyObject *py_meta, uint32_t *ttl_ref, - uint16_t *gen_ref, as_error *err, - bool validate_keys) +as_status check_and_set_meta(PyObject *py_meta, uint16_t *gen_ref, + as_error *err, bool validate_keys) { as_error_reset(err); if (py_meta && PyDict_Check(py_meta)) { @@ -2451,39 +2452,7 @@ as_status check_and_set_meta(PyObject *py_meta, uint32_t *ttl_ref, } PyObject *py_gen = PyDict_GetItemString(py_meta, "gen"); - PyObject *py_ttl = PyDict_GetItemString(py_meta, "ttl"); - uint32_t ttl = 0; uint16_t gen = 0; - if (py_ttl) { - int retval = - PyErr_WarnEx(PyExc_DeprecationWarning, - META_TTL_DEPRECATION_MESSAGE, STACK_LEVEL); - if (retval == -1) { - // This handles the codepath where warnings are converted into errors from pytest/python cli - // TODO: this does NOT handle the codepath where the warning mechanism itself fails - return as_error_update(err, AEROSPIKE_ERR, - META_TTL_DEPRECATION_MESSAGE); - } - - if (PyLong_Check(py_ttl)) { - ttl = (uint32_t)PyLong_AsLong(py_ttl); - } - else { - return as_error_update(err, AEROSPIKE_ERR_PARAM, - "Ttl should be an int or long"); - } - - if ((uint32_t)-1 == ttl && PyErr_Occurred()) { - return as_error_update( - err, AEROSPIKE_ERR_PARAM, - "integer value for ttl exceeds sys.maxsize"); - } - *ttl_ref = ttl; - } - else { - // Metadata dict was present, but ttl field did not exist - *ttl_ref = AS_RECORD_CLIENT_DEFAULT_TTL; - } if (py_gen) { if (PyLong_Check(py_gen)) { @@ -2507,10 +2476,6 @@ as_status check_and_set_meta(PyObject *py_meta, uint32_t *ttl_ref, return as_error_update(err, AEROSPIKE_ERR_PARAM, "Metadata should be of type dictionary"); } - else { - // Metadata dict was not set by user - *ttl_ref = AS_RECORD_CLIENT_DEFAULT_TTL; - } return err->code; } diff --git a/test/new_tests/test_client_config_level_options.py b/test/new_tests/test_client_config_level_options.py index d47d2dcb16..c472e353b1 100644 --- a/test/new_tests/test_client_config_level_options.py +++ b/test/new_tests/test_client_config_level_options.py @@ -567,9 +567,8 @@ def config_ttl_setup(self, policy_name: str): [ {"meta": None}, {"meta": {"gen": 10}}, - {"meta": {"ttl": aerospike.TTL_CLIENT_DEFAULT, "gen": 10}}, {"policy": None}, - # {"policy": {}}, + {"policy": {}}, ] ) diff --git a/test/new_tests/test_command_level_policies.py b/test/new_tests/test_command_level_policies.py index de92979bdc..afec927b9c 100644 --- a/test/new_tests/test_command_level_policies.py +++ b/test/new_tests/test_command_level_policies.py @@ -17,20 +17,19 @@ class CommandLevelTTL: NEW_TTL = 3000 POLICY = {"ttl": NEW_TTL} - meta_and_policy_params = pytest.mark.parametrize( + policy_params = pytest.mark.parametrize( "kwargs_with_ttl", [ - {"meta": POLICY}, {"policy": POLICY}, ] ) - @meta_and_policy_params + @policy_params def test_write_policy(self, kwargs_with_ttl): self.as_connection.put(KEY, bins={"a": 1}, **kwargs_with_ttl) verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) - @meta_and_policy_params + @policy_params def test_operate_policy(self, kwargs_with_ttl): ops = [ operations.write(bin_name="a", write_item=1) @@ -50,33 +49,15 @@ def test_batch_operate(self): verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) - # Don't bother testing for DeprecationWarnings here since running Python with -W error flag can - # cause ClientError to be raised. It's too complicated to check both cases - @pytest.mark.filterwarnings("ignore::DeprecationWarning") - @meta_and_policy_params + @policy_params def test_batch_write(self, kwargs_with_ttl): batch_records = br.BatchRecords([ br.Write(KEY, ops=self.OPS, **kwargs_with_ttl) ]) - try: - self.as_connection.batch_write(batch_records) - except e.ClientError as exc: - # ClientError can be raised if the user runs Python with warnings treated as errors. - assert exc.msg == "meta[\"ttl\"] is deprecated and will be removed in the next client major release" + self.as_connection.batch_write(batch_records) verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) - # This test case is more important when warnings are converted into errors - @pytest.mark.filterwarnings("ignore::DeprecationWarning") - def test_batch_write_with_read_br_raises_deprecation_warning(self): - batch_records = br.BatchRecords([ - br.Read(KEY, meta={"ttl": 100}) - ]) - try: - self.client.batch_write(batch_records) - except e.ClientError as exc: - assert exc.msg == "meta[\"ttl\"] is deprecated and will be removed in the next client major release" - def test_scan_policy(self): ops = [ operations.write(bin_name="a", write_item=1) diff --git a/test/new_tests/test_remove.py b/test/new_tests/test_remove.py index 6cbf0ce4c9..35bfabf7db 100644 --- a/test/new_tests/test_remove.py +++ b/test/new_tests/test_remove.py @@ -38,7 +38,6 @@ def test_pos_remove_with_existing_record(self, setup_for_pos_tests): @pytest.mark.parametrize( "kwargs", [ - {"meta": {"gen": 0}}, {"policy": {"generation": 0, "total_timeout": 180000}}, ] ) @@ -48,14 +47,7 @@ def test_pos_remove_with_policy(self, setup_for_pos_tests, kwargs): """ key = ("test", "demo", 1) - if "meta" in kwargs: - cm = pytest.warns(DeprecationWarning) - else: - cm = nullcontext() - - with cm: - retobj = self.as_connection.remove(key, **kwargs) - + retobj = self.as_connection.remove(key, **kwargs) assert retobj == 0 with pytest.raises(e.RecordNotFound) as exception: @@ -244,11 +236,9 @@ def test_neg_remove_with_extra_parameter(self): Invoke remove() with extra parameter """ key = ("test", "demo", 1) - meta = {"gen": 0} policy = {} with pytest.raises(TypeError) as typeError: - self.as_connection.remove(key, meta, policy, "Extra Param") - assert "remove() takes at most 3 arguments (4 given)" in str(typeError.value) + self.as_connection.remove(key, policy, "Extra Param") @pytest.mark.parametrize("key, ex_code, ex_msg", key_neg) def test_neg_remove_with_incorrect_data(self, key, ex_code, ex_msg): diff --git a/test/new_tests/test_validate_keys.py b/test/new_tests/test_validate_keys.py index c7b56e10fc..bb032a344c 100644 --- a/test/new_tests/test_validate_keys.py +++ b/test/new_tests/test_validate_keys.py @@ -112,15 +112,21 @@ def test_invalid_policy_keys(self, api_method: Callable, kwargs: dict, context_i if self.config["validate_keys"]: assert EXPECTED_ERROR_MESSAGE in excinfo.value.msg - def test_invalid_metadata_dictionary_key(self): - INVALID_METADATA_KEY = "generation" + @pytest.mark.parametrize( + "metadata_key", + [ + "generation", + "ttl" + ] + ) + def test_invalid_metadata_dictionary_key(self, metadata_key): if self.config["validate_keys"]: - EXPECTED_ERROR_MESSAGE = f"\"{INVALID_METADATA_KEY}\" is an invalid record metadata dictionary key" + EXPECTED_ERROR_MESSAGE = f"\"{metadata_key}\" is an invalid record metadata dictionary key" context = EXPECTED_CONTEXT_IF_VALIDATE_KEYS_ENABLED else: context = nullcontext() - meta = {INVALID_METADATA_KEY: 1} + meta = {metadata_key: 1} with context as excinfo: self.as_connection.put(key=KEY, bins={"a": 1}, meta=meta)