From a1c873e63c80562a127470e1ff5609f433fdd086 Mon Sep 17 00:00:00 2001 From: Kevan Carstensen Date: Mon, 16 Nov 2015 14:58:47 -0800 Subject: [PATCH] Ensure that we don't double add things to self.order. If we do this, then we'll try and fail to evict the same key combination multiple times, leading to KeyErrors. --- lib/pyld/jsonld.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index a7799c39..01bd353f 100755 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -5089,7 +5089,12 @@ def set(self, active_ctx, local_ctx, result): del self.cache[entry['activeCtx']][entry['localCtx']] key1 = json.dumps(active_ctx) key2 = json.dumps(local_ctx) - self.order.append({'activeCtx': key1, 'localCtx': key2}) + # if we haven't seen this key combination before, add it to the deque. + # (if it already exists -- i.e., if we're overwriting an existing + # value -- then it's already contained in the deque, and we shouldn't + # do anything) + if key1 not in self.cache or key2 not in self.cache[key1]: + self.order.append({'activeCtx': key1, 'localCtx': key2}) self.cache.setdefault(key1, {})[key2] = json.loads(json.dumps(result))