From 0a4e531567ce9f39d3af48e3e657bcac461aea09 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Thu, 17 Mar 2016 15:48:52 -0400 Subject: [PATCH] Drop look-before-leap use of protobuf-internal type checker. The protobuf itself will raise the error when an out-of-bounds int/long value is assigned. Addresses: https://github.com/google/protobuf/issues/1307#issuecomment-197596703. --- gcloud/datastore/helpers.py | 6 +----- gcloud/datastore/test_helpers.py | 8 -------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/gcloud/datastore/helpers.py b/gcloud/datastore/helpers.py index 9db96eb83705..b9b8863dabcc 100644 --- a/gcloud/datastore/helpers.py +++ b/gcloud/datastore/helpers.py @@ -19,7 +19,6 @@ import datetime -from google.protobuf.internal.type_checkers import Int64ValueChecker import six from gcloud._helpers import _datetime_from_microseconds @@ -30,8 +29,6 @@ __all__ = ('entity_from_protobuf', 'key_from_protobuf') -INT_VALUE_CHECKER = Int64ValueChecker() - def find_true_project(project, connection): """Find the true (unaliased) project. @@ -318,8 +315,7 @@ def _pb_attr_value(val): elif isinstance(val, float): name, value = 'double', val elif isinstance(val, six.integer_types): - INT_VALUE_CHECKER.CheckValue(val) # Raise an exception if invalid. - name, value = 'integer', int(val) # Always cast to an integer. + name, value = 'integer', val elif isinstance(val, six.text_type): name, value = 'string', val elif isinstance(val, (bytes, str)): diff --git a/gcloud/datastore/test_helpers.py b/gcloud/datastore/test_helpers.py index af746a154c9d..7d86382e7f32 100644 --- a/gcloud/datastore/test_helpers.py +++ b/gcloud/datastore/test_helpers.py @@ -457,14 +457,6 @@ def test_long(self): self.assertEqual(name, 'integer_value') self.assertEqual(value, must_be_long) - def test_long_too_small(self): - too_small = -(1 << 63) - 1 - self.assertRaises(ValueError, self._callFUT, too_small) - - def test_long_too_large(self): - too_large = 1 << 63 - self.assertRaises(ValueError, self._callFUT, too_large) - def test_native_str(self): import six name, value = self._callFUT('str')