Skip to content

Commit

Permalink
fix issue where using the index to query graphs could throw unexpecte…
Browse files Browse the repository at this point in the history
…d KeyErrors
  • Loading branch information
LG Dev committed Nov 29, 2018
1 parent 7c8503c commit a3baeb2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions LemonGraph/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def idx_users(self, obj):

class StatusIndex(object):
domain = 'status'
null = Serializer.null()

def __init__(self, ctx):
self.ctx = ctx
Expand All @@ -90,7 +91,7 @@ def _index(self, idx):
try:
return self._indexes[idx]
except KeyError:
self._indexes[idx] = self.ctx.txn.sset('lg.collection.idx.%s.%s' % (self.domain, idx))
self._indexes[idx] = self.ctx.txn.sset('lg.collection.idx.%s.%s' % (self.domain, idx), serialize_value=self.null)
return self._indexes[idx]

def search(self, idx, value):
Expand All @@ -101,7 +102,7 @@ def search(self, idx, value):
except KeyError:
return
for key in index.iterpfx(pfx=crc):
uuid = key[crclen:]
uuid = key[crclen:].decode()
status = self.ctx.statusDB[uuid]
if check(status):
yield uuid, status
Expand Down
6 changes: 6 additions & 0 deletions LemonGraph/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def unpack_from_wrapper(*args, **kwargs):
# for node/edge types/values as well as property keys, you should strive to make sure the encoder is deterministic
# if you plan to use complex values - if dicts are involved, msgpack is not so much.

def identity(x):
return x

class Serializer(object):
@staticmethod
Expand Down Expand Up @@ -99,6 +101,10 @@ def decode(b):

return Serializer(encode=encode, decode=decode)

@classmethod
def null(cls):
return Serializer(encode=identity, decode=identity)

@classmethod
def uints(cls, count, decode_type=tuple, string=False):
if string:
Expand Down

0 comments on commit a3baeb2

Please sign in to comment.