Skip to content

Commit

Permalink
fix on uuid encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
phenobarbital committed Apr 7, 2022
1 parent 8ef6bd5 commit 5dc1857
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions asyncdb/utils/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,30 @@ def default(self, obj):
return str(obj)
elif isinstance(obj, timedelta):
return obj.__str__()
elif hasattr(obj, "hex"):
return obj.hex
elif isinstance(obj, Enum):
if not obj.value:
return None
else:
return str(obj.value)
elif isinstance(obj, uuid.UUID):
try:
return str(obj)
except ValueError:
if uobj := uuid.UUID(obj, version=4):
return str(uobj)
except ValueError:
return str(obj)
elif isinstance(obj, decimal.Decimal):
return float(obj)
elif isinstance(obj, Decimal):
return str(obj)
elif hasattr(obj, "isoformat"):
try:
return obj.isoformat()
except TypeError:
return None
return obj.isoformat()
elif isinstance(obj, asyncpg.Range):
return [obj.lower, obj.upper]
elif hasattr(obj, "hex"):
return obj.hex
else:
# return str(obj)
raise TypeError("%r is not JSON serializable" % obj)
raise TypeError(f"{obj!r} is not JSON serializable")


class BaseEncoder:
Expand Down

0 comments on commit 5dc1857

Please sign in to comment.