DEV Community

Thomas Eyde
Thomas Eyde

Posted on

TableClient PropertyValueTooLarge exception message may be incorrect

I observed the following exception in the logs a few days ago:

---> Azure.RequestFailedException: The property value exceeds the maximum allowed size (64KB). If the property value is a string, it is UTF-16 encoded and the maximum number of characters should be 32K or less.
RequestId:fb842d88-5002-002e-363f-1342d7000000
Time:2024-09-30T13:50:16.5210829Z
Status: 400 (Bad Request)
ErrorCode: PropertyValueTooLarge
Enter fullscreen mode Exit fullscreen mode

This exception has a few issues:

  1. It does not tell which property which is too long.
  2. The message is wrong if the property is PartitionKey or RowKey.

Worse, the documentation is also incorrect:

RowKey Property
(...)
The row key is a string value that may be up to 1024 characters in size.

https://learn.microsoft.com/en-us/rest/api/storageservices/understanding-the-table-service-data-model#rowkey-property

There is a difference between characters and bytes. If the text is UTF-16, the limit is 512 characters.

It took me long enough to narrow down the issue, which was RowKey being too long.

My solution:

  1. Generate the candidate key, may be too long with invalid characters
  2. Create a Crc32 hash and prepend to the candidate
  3. Truncate this to max 512 characters

The hash will ensure a unique RowKey in case two truncated candidates should be the same.

Top comments (0)