Azure/azure-sdk-for-python

_to_entity_int32 is not appropriate for Python integers

minerjaime opened this issue · 4 comments

I have a use case where I'd like to use Python integer values within my Cosmos DB table. When the integer values exceed the size allotted to an EdmType.INT32, I receive errors.

Since Python isn't bound to the same size limitations for its integers, can we get a more appropriate "_to_entity" function for handling Python ints?

I would propose this:
def _to_entity_int(value):
int_value = int(value)
if int_value >= 2**63 or int_value < -(2**63):
raise TypeError(_ERROR_VALUE_TOO_LARGE.format(str(int_value), EdmType.INT64))
if int_value >= 2**31 or int_value < -(2**31):
return EdmType.INT64, str(value)
else:
return None, value

Thank you so much!

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @klaaslanghout.

To bypass this issue, I have resorted to storing these particular "large" int values as strings and making the appropriate casts in the python code.

Hi @minerjaime - thanks for opening an issue! We'll take a look asap!

Hi @minerjaime , we've noticed the inappropriate encoding in Tables and we're working on it. We'll ship a beta with new encoding in next month, stay tuned!