Skip to content

Commit

Permalink
Raise an error on too long string attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Toker committed Jul 17, 2024
1 parent 37506fa commit 9decd79
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
14 changes: 13 additions & 1 deletion v3io/dataplane/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,29 @@ 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

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)
Expand Down

0 comments on commit 9decd79

Please sign in to comment.