Skip to content

Commit 720e723

Browse files
committed
Fix hashing of geojson objects.
1 parent 9e7a6e5 commit 720e723

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

ppp_datamodel/nodes/resource.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def _parse_value(value, attributes):
9999
def _format_value(value):
100100
return value
101101

102+
def freeze_dicts(d):
103+
if isinstance(d, dict):
104+
return frozenset(map(lambda x:(x[0], freeze_dicts(x[1])), d.items()))
105+
elif isinstance(d, list):
106+
return tuple(map(freeze_dicts, d))
107+
else:
108+
return d
109+
102110
@register_valuetype
103111
class GeojsonResource(Resource):
104112
_value_type = 'geo-json'
@@ -110,3 +118,6 @@ def deserialize_attribute(cls, key, value):
110118
return value
111119
else:
112120
super().deserialize_attribute(key, value)
121+
122+
def __hash__(self):
123+
return hash(freeze_dicts(self._attributes))

tests/test_resource.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ def testGeojson(self):
3939
}
4040
o = AbstractNode.from_dict(d)
4141
self.assertEqual(o.geojson['type'], 'Feature')
42+
hash(o)

0 commit comments

Comments
 (0)