davebshow / goblin

A Python 3.5 rewrite of the TinkerPop 3 OGM Goblin
Other
93 stars 21 forks source link

properties error using integer value of zero #72

Closed John-Boik closed 7 years ago

John-Boik commented 7 years ago

Hi Dave. If I create a vertex class with an integer property that has a meta-property, and then set that property value to zero, I loose the Goblin.Integer type.

class vclass(goblin.VertexProperty):
  notes = goblin.Property(goblin.String)

class myclass (goblin.Vertex):
  id1 = vclass(goblin.Integer, card=Cardinality.list_)
  id2 = vclass(goblin.Integer, card=Cardinality.list_)

a = myclass()
setattr(a, 'id1', 0)
setattr(a, 'id2', '0')
print(a.__dict__)

This results in: {'_id1': 0, '_id2': [<vclass(type=<goblin.properties.Integer object at 0x7f38c1586780>, value=0)]}

This problem is not seen if the value is not zero. For example:

a = myclass()
setattr(a, 'id1', 1)
setattr(a, 'id2', '1')
print(a.__dict__)

This results in the expected behavior: {'_id1': [<vclass(type=<goblin.properties.Integer object at 0x7f38c15866a0>, value=1)], '_id2': [<vclass(type=<goblin.properties.Integer object at 0x7f38c1586780>, value=1)]}

davebshow commented 7 years ago

This was a small bug in the VertexPropertyDescriptor fixed in 5a6f95ba43d3e066f4f31d97d879c7dd2bb7824a. Please install Goblin from Github and confirm the fix:

pip install git+https://github.com/davebshow/goblin.git

I hope to get to your other issue this evening.

davebshow commented 7 years ago

Can I close this as well?

John-Boik commented 7 years ago

Great! It solved my problem.