Skip to content

Commit

Permalink
Fix JSON field raising a db integrity error for app side data
Browse files Browse the repository at this point in the history
  • Loading branch information
enpaul committed May 4, 2023
1 parent d33dae2 commit 7944d4d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion peewee_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ class JSONField(peewee.TextField): # pylint: disable=abstract-method
:param dump_params: Additional keyword arguments to unpack into :func:`json.dump`
:param load_params: Additional keyword arguments to unpack into :func:`json.load`
:raises ValueError: When attempting to set a non-JSON serializable object to the field
:raises peewee.IntegrityError: When the underlying database value is not JSON serializable
"""

def __init__(
Expand All @@ -334,7 +336,7 @@ def db_value(self, value: Any) -> str:
try:
return super().db_value(json.dumps(value, **self.dump_params))
except TypeError as err:
raise peewee.IntegrityError(
raise ValueError(
f"Failed to JSON encode object of type '{type(value)}'"
) from err

Expand Down

0 comments on commit 7944d4d

Please sign in to comment.