diff --git a/tests/test_client.py b/tests/test_client.py index ab0ab0a..73646ff 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -446,6 +446,15 @@ def _get_float_array(): for key in item[item_key]: self._compare_item_types(item[item_key][key], response.output.item[key]) + item = {item_key: {"large_string": "a" * 61200}} + try: + self._client.kv.put( + container=self._container, table_path=self._path, key=item_key, attributes=item[item_key] + ) + self.fail("Large string should have raised an exception") + except AttributeError: + pass + def test_kv(self): items = { "bob": {"age": 42, "feature": "mustache"}, diff --git a/v3io/dataplane/request.py b/v3io/dataplane/request.py index a74adc0..1983c11 100644 --- a/v3io/dataplane/request.py +++ b/v3io/dataplane/request.py @@ -414,7 +414,7 @@ def _to_base64(input): def _dict_to_typed_attributes(d): typed_attributes = {} - + max_string_length = 61199 for key, value in future.utils.viewitems(d): attribute_type = type(value) type_value = None @@ -422,9 +422,21 @@ def _dict_to_typed_attributes(d): if isinstance(value, future.utils.text_type): type_key = "S" type_value = value + if len(value) > max_string_length: + raise AttributeError( + "Attribute {0} is too long({1} bytes) when max is {2} bytes".format( + key, len(value), max_string_length + ) + ) elif isinstance(value, future.utils.string_types): type_key = "S" type_value = str(value) + if len(type_value) > max_string_length: + raise AttributeError( + "Attribute {0} is too long({1} bytes) when max is {2} bytes".format( + key, len(value), max_string_length + ) + ) elif attribute_type in [int, float]: type_key = "N" type_value = str(value)