Repository: davebshow/goblin

Issue:
64-bit Integer Properties
`goblin.Integer` uses the built-in python `int` for validating whether a given value is integer (https://github.com/davebshow/goblin/blob/master/goblin/properties.py#L175). However, this causes problems with 64-bit integers. For example, `list` and `set` cardinality creates `*VertexPropertyManager` instances that call validate on each argument they are given.

In order to support correct GraphSON serialization to `Int64`, `gremlin_python` creates a `long` type in `gremlin_python.statics`. Developers should cast integers to that sub-class of `int` if they want them to be serialized correctly to the database. Sets of 64-bit integers, however, get cast back to the 32-bit `int` because of the validator.

I propose replacing the existing validate with:

```python
                if not isinstance(val, long):
                    return int(val)
                else:
                    return val
```

where `long` is `from gremlin_python.statics import long`. Happy to pull request for this again.

Discussion:

Patch:
diff --git a/goblin/properties.py b/goblin/properties.py
index f803052..912bb20 100644
--- a/goblin/properties.py
+++ b/goblin/properties.py
@@ -172,6 +172,8 @@ class Integer(abc.DataType):
     def validate(self, val):
         if val is not None:
             try:
+                if isinstance(val, long):
+                    return long(val)
                 return int(val)
             except (ValueError, TypeError) as e:
                 raise exception.ValidationError(


Test patch:
diff --git a/tests/test_properties.py b/tests/test_properties.py
index bb7a620..c264e5a 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -144,6 +144,10 @@ def test_set_change_set_card_vertex_property(place):
 def test_set_card_union(place):
     place.important_numbers = set([1, 2, 3])
     place.important_numbers = place.important_numbers.union({3, 4, 5})
+
+def test_set_card_64bit_integer(place):
+    place.important_numbers = set([long(1), long(2), long(3)])
+    assert all(isinstance(i.value, long) for i in place.important_numbers)
         
 def test_set_card_validation_vertex_property(place):
     with pytest.raises(exception.ValidationError):