Dynamoid icon indicating copy to clipboard operation
Dynamoid copied to clipboard

String max length

Open samwho opened this issue 11 years ago • 2 comments

When you call write_attribute here: https://github.com/Veraticus/Dynamoid/blob/master/lib/dynamoid/fields.rb#L73

You're checking the length of the string with size when it should actually be bytesize. Also, the length of things aren't constrained unless they're a primary or range key.

Relevant documentation:

  • http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html
  • http://ruby-doc.org/core-2.0.0/String.html#method-i-size

samwho avatar Dec 19 '13 10:12 samwho

.size and .bytesize on a string are the same thing since a character is a byte and .size returns the number of characters.

Also, the size limit applies to the object as a whole. In fact you cannot store items greater than 400KB (so the limit should be raised to 400KB from 64KB which is the old limit). This check is somewhat pointless though since it doesn't check total item size, but is still somewhat useful as a sanity check.

ngordon17 avatar Mar 20 '15 06:03 ngordon17

The strings in DynamoDB are UTF-8 (it says in one of the links I put in the original post), which doesn't guarantee that one character is one byte in length. For more information, this is an excellent read: http://www.joelonsoftware.com/articles/Unicode.html.

samwho avatar Mar 20 '15 10:03 samwho