diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py b/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py index 6b16a8f288bd..913e5de9a0a5 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py @@ -160,7 +160,10 @@ def _convert_to_entity(entry_element): # Add type for Int32 if type(value) is int: # pylint:disable=C0123 - mtype = EdmType.INT32 + if value.bit_length() <= 32: + mtype = EdmType.INT32 + else: + mtype = EdmType.INT64 # no type info, property should parse automatically if not mtype: diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_entity.py b/sdk/tables/azure-data-tables/azure/data/tables/_entity.py index 230eb402e16d..41e9a3a1d588 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_entity.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_entity.py @@ -101,7 +101,10 @@ def __init__(self, elif isinstance(value, bool): self.type = EdmType.BOOLEAN elif isinstance(value, six.integer_types): - self.type = EdmType.INT64 + if value.bit_length() <= 32: + self.type = EdmType.INT32 + else: + self.type = EdmType.INT64 elif isinstance(value, datetime): self.type = EdmType.DATETIME elif isinstance(value, float): diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_serialize.py b/sdk/tables/azure-data-tables/azure/data/tables/_serialize.py index f937d68f3b72..56e7cae7598d 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_serialize.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_serialize.py @@ -133,6 +133,15 @@ def _to_entity_int64(value): return EdmType.INT64, str(value) +def _to_entity_int(value): + ivalue = int(value) + if ivalue.bit_length() <= 32: + return _to_entity_int32(value) + if ivalue.bit_length() <= 64: + return _to_entity_int64(value) + raise TypeError(_ERROR_VALUE_TOO_LARGE.format(str(value), EdmType.INT64)) + + def _to_entity_str(value): return None, value @@ -144,7 +153,7 @@ def _to_entity_none(value): # pylint:disable=W0613 # Conversion from Python type to a function which returns a tuple of the # type string and content string. _PYTHON_TO_ENTITY_CONVERSIONS = { - int: _to_entity_int64, + int: _to_entity_int, bool: _to_entity_bool, datetime: _to_entity_datetime, float: _to_entity_float, diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_table_client.py b/sdk/tables/azure-data-tables/azure/data/tables/_table_client.py index e5490732c170..47861d843a87 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_table_client.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_table_client.py @@ -32,7 +32,7 @@ from ._serialize import serialize_iso from ._deserialize import _return_headers_and_deserialized from ._error import _process_table_error -from ._models import TableEntityPropertiesPaged, UpdateMode, TableItem +from ._models import TableEntityPropertiesPaged, UpdateMode class TableClient(TableClientBase): diff --git a/sdk/tables/azure-data-tables/tests/recordings/test_table_entity.test_insert_entity_with_large_int32_value_throws.yaml b/sdk/tables/azure-data-tables/tests/recordings/test_table_entity.test_insert_entity_with_large_int32_value_throws.yaml index 65617ef23a9f..c944d845b6a3 100644 --- a/sdk/tables/azure-data-tables/tests/recordings/test_table_entity.test_insert_entity_with_large_int32_value_throws.yaml +++ b/sdk/tables/azure-data-tables/tests/recordings/test_table_entity.test_insert_entity_with_large_int32_value_throws.yaml @@ -15,13 +15,13 @@ interactions: DataServiceVersion: - '3.0' Date: - - Thu, 20 Aug 2020 20:16:40 GMT + - Mon, 31 Aug 2020 22:27:33 GMT User-Agent: - - azsdk-python-data-tables/2019-07-07 Python/3.8.4 (Windows-10-10.0.19041-SP0) + - azsdk-python-data-tables/12.0.0b1 Python/3.8.4 (Windows-10-10.0.19041-SP0) x-ms-date: - - Thu, 20 Aug 2020 20:16:40 GMT + - Mon, 31 Aug 2020 22:27:33 GMT x-ms-version: - - '2019-07-07' + - '2019-02-02' method: POST uri: https://storagename.table.core.windows.net/Tables response: @@ -33,7 +33,7 @@ interactions: content-type: - application/json;odata=minimalmetadata;streaming=true;charset=utf-8 date: - - Thu, 20 Aug 2020 20:16:40 GMT + - Mon, 31 Aug 2020 22:27:30 GMT location: - https://storagename.table.core.windows.net/Tables('uttable8fac1b18') server: @@ -43,7 +43,7 @@ interactions: x-content-type-options: - nosniff x-ms-version: - - '2019-07-07' + - '2019-02-02' status: code: 201 message: Created @@ -59,13 +59,13 @@ interactions: Content-Length: - '0' Date: - - Thu, 20 Aug 2020 20:16:40 GMT + - Mon, 31 Aug 2020 22:27:33 GMT User-Agent: - - azsdk-python-data-tables/2019-07-07 Python/3.8.4 (Windows-10-10.0.19041-SP0) + - azsdk-python-data-tables/12.0.0b1 Python/3.8.4 (Windows-10-10.0.19041-SP0) x-ms-date: - - Thu, 20 Aug 2020 20:16:40 GMT + - Mon, 31 Aug 2020 22:27:33 GMT x-ms-version: - - '2019-07-07' + - '2019-02-02' method: DELETE uri: https://storagename.table.core.windows.net/Tables('uttable8fac1b18') response: @@ -77,13 +77,13 @@ interactions: content-length: - '0' date: - - Thu, 20 Aug 2020 20:16:40 GMT + - Mon, 31 Aug 2020 22:27:30 GMT server: - Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0 x-content-type-options: - nosniff x-ms-version: - - '2019-07-07' + - '2019-02-02' status: code: 204 message: No Content diff --git a/sdk/tables/azure-data-tables/tests/test_table_batch.py b/sdk/tables/azure-data-tables/tests/test_table_batch.py index ba8603f9703f..946280be374a 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_batch.py +++ b/sdk/tables/azure-data-tables/tests/test_table_batch.py @@ -163,7 +163,7 @@ def test_inferred_types(self): entity.test5 = EntityProperty(u"stringystring") entity.test6 = EntityProperty(3.14159) entity.test7 = EntityProperty(100) - entity.test8 = EntityProperty(10, EdmType.INT32) + entity.test8 = EntityProperty(2 ** 33) # Assert self.assertEqual(entity.test.type, EdmType.BOOLEAN) @@ -172,8 +172,8 @@ def test_inferred_types(self): self.assertEqual(entity.test4.type, EdmType.DATETIME) self.assertEqual(entity.test5.type, EdmType.STRING) self.assertEqual(entity.test6.type, EdmType.DOUBLE) - self.assertEqual(entity.test7.type, EdmType.INT64) - self.assertEqual(entity.test8.type, EdmType.INT32) + self.assertEqual(entity.test7.type, EdmType.INT32) + self.assertEqual(entity.test8.type, EdmType.INT64) @pytest.mark.skip("pending") diff --git a/sdk/tables/azure-data-tables/tests/test_table_entity.py b/sdk/tables/azure-data-tables/tests/test_table_entity.py index 149b70ddf49d..03b0775e155f 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_entity.py +++ b/sdk/tables/azure-data-tables/tests/test_table_entity.py @@ -160,7 +160,7 @@ def _assert_default_entity(self, entity, headers=None): self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc())) self.assertEqual(entity['binary'].value, b'binary') self.assertIsInstance(entity['other'], EntityProperty) - self.assertEqual(entity['other'].type, EdmType.INT64) + self.assertEqual(entity['other'].type, EdmType.INT32) self.assertEqual(entity['other'].value, 20) self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833')) # self.assertTrue('metadata' in entity.odata) @@ -188,7 +188,7 @@ def _assert_default_entity_json_full_metadata(self, entity, headers=None): self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc())) self.assertEqual(entity['binary'].value, b'binary') self.assertIsInstance(entity['other'], EntityProperty) - self.assertEqual(entity['other'].type, EdmType.INT64) + self.assertEqual(entity['other'].type, EdmType.INT32) self.assertEqual(entity['other'].value, 20) self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833')) # self.assertTrue('metadata' in entity.odata) @@ -222,7 +222,7 @@ def _assert_default_entity_json_no_metadata(self, entity, headers=None): self.assertTrue(entity['birthday'].endswith('00Z')) self.assertEqual(entity['binary'], b64encode(b'binary').decode('utf-8')) self.assertIsInstance(entity['other'], EntityProperty) - self.assertEqual(entity['other'].type, EdmType.INT64) + self.assertEqual(entity['other'].type, EdmType.INT32) self.assertEqual(entity['other'].value, 20) self.assertEqual(entity['clsid'], 'c9da6455-213d-42c9-9a79-3e9149a57833') # self.assertIsNone(entity.odata) @@ -273,7 +273,7 @@ def _assert_merged_entity(self, entity): self.assertEqual(entity.Birthday, datetime(1973, 10, 4, tzinfo=tzutc())) self.assertEqual(entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc())) self.assertIsInstance(entity.other, EntityProperty) - self.assertEqual(entity.other.type, EdmType.INT64) + self.assertEqual(entity.other.type, EdmType.INT32) self.assertEqual(entity.other.value, 20) self.assertIsInstance(entity.clsid, uuid.UUID) self.assertEqual(str(entity.clsid), 'c9da6455-213d-42c9-9a79-3e9149a57833') diff --git a/sdk/tables/azure-data-tables/tests/test_table_entity_async.py b/sdk/tables/azure-data-tables/tests/test_table_entity_async.py index c962d20ddf3c..e5f012be9bd2 100644 --- a/sdk/tables/azure-data-tables/tests/test_table_entity_async.py +++ b/sdk/tables/azure-data-tables/tests/test_table_entity_async.py @@ -161,7 +161,7 @@ def _assert_default_entity(self, entity, headers=None): self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc())) self.assertEqual(entity['binary'].value, b'binary') # TODO: added the ".value" portion, verify this is correct self.assertIsInstance(entity['other'], EntityProperty) - self.assertEqual(entity['other'].type, EdmType.INT64) + self.assertEqual(entity['other'].type, EdmType.INT32) self.assertEqual(entity['other'].value, 20) self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833')) # self.assertTrue('metadata' in entity.odata) @@ -190,7 +190,7 @@ def _assert_default_entity_json_full_metadata(self, entity, headers=None): self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc())) self.assertEqual(entity['binary'].value, b'binary') self.assertIsInstance(entity['other'], EntityProperty) - self.assertEqual(entity['other'].type, EdmType.INT64) + self.assertEqual(entity['other'].type, EdmType.INT32) self.assertEqual(entity['other'].value, 20) self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833')) # self.assertTrue('metadata' in entity.odata) @@ -225,7 +225,7 @@ def _assert_default_entity_json_no_metadata(self, entity, headers=None): self.assertTrue(entity['birthday'].endswith('00Z')) self.assertEqual(entity['binary'], b64encode(b'binary').decode('utf-8')) self.assertIsInstance(entity['other'], EntityProperty) - self.assertEqual(entity['other'].type, EdmType.INT64) + self.assertEqual(entity['other'].type, EdmType.INT32) self.assertEqual(entity['other'].value, 20) self.assertEqual(entity['clsid'], 'c9da6455-213d-42c9-9a79-3e9149a57833') # self.assertIsNone(entity.odata) @@ -275,7 +275,7 @@ def _assert_merged_entity(self, entity): self.assertEqual(entity.Birthday, datetime(1973, 10, 4, tzinfo=tzutc())) self.assertEqual(entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc())) self.assertIsInstance(entity.other, EntityProperty) - self.assertEqual(entity.other.type, EdmType.INT64) + self.assertEqual(entity.other.type, EdmType.INT32) self.assertEqual(entity.other.value, 20) self.assertIsInstance(entity.clsid, uuid.UUID) self.assertEqual(str(entity.clsid), 'c9da6455-213d-42c9-9a79-3e9149a57833')