From 7944d4de48ed4ef8fb347dbd8a42dd4e6d738977 Mon Sep 17 00:00:00 2001 From: Ethan Paul <24588726+enpaul@users.noreply.github.com> Date: Thu, 4 May 2023 15:08:47 -0400 Subject: [PATCH] Fix JSON field raising a db integrity error for app side data --- peewee_plus.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/peewee_plus.py b/peewee_plus.py index 23f1799..350d15a 100644 --- a/peewee_plus.py +++ b/peewee_plus.py @@ -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__( @@ -334,7 +336,7 @@ class JSONField(peewee.TextField): # pylint: disable=abstract-method 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