Skip to content

Commit

Permalink
Merge pull request #16 from onecodex/master
Browse files Browse the repository at this point in the history
Make PotionJSONEncoder serialize self-references
  • Loading branch information
lyschoening committed Nov 6, 2016
2 parents 9fa46a7 + af46cf8 commit 27b72d8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions potion_client/converter.py
Expand Up @@ -32,6 +32,7 @@ def dst(self, dt):

class PotionJSONEncoder(JSONEncoder):
def encode(self, o):
root_id = id(o)
if self.check_circular:
markers = {}
else:
Expand All @@ -42,6 +43,8 @@ def _encode(o):
if markers is not None:
marker_id = id(o)
if marker_id in markers:
if marker_id == root_id:
return {"$ref": "#"}
raise ValueError("Circular reference detected")
markers[marker_id] = o
try:
Expand Down

0 comments on commit 27b72d8

Please sign in to comment.