Skip to content

Commit

Permalink
Make PotionJSONEncoder serialize self-references (e.g. to re-serializ…
Browse files Browse the repository at this point in the history
…e PotionJSONSchemaDecoder output)
  • Loading branch information
Roderick Bovee committed Sep 21, 2016
1 parent ba79269 commit af46cf8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions potion_client/converter.py
Original file line number Diff line number Diff line change
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 af46cf8

Please sign in to comment.