From 5c5b4d0f5f22696ba2613360be60b2b2b976c385 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:52:30 -0300 Subject: [PATCH] fix: JSON loading logs (#30138) --- superset/utils/json.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/superset/utils/json.py b/superset/utils/json.py index cc2ab400c021a..0c62d7640e4c7 100644 --- a/superset/utils/json.py +++ b/superset/utils/json.py @@ -174,7 +174,11 @@ def validate_json(obj: Union[bytes, bytearray, str]) -> None: :param obj: an object that should be parseable to JSON """ if obj: - loads(obj) + try: + loads(obj) + except JSONDecodeError as ex: + logger.error("JSON is not valid %s", str(ex), exc_info=True) + raise def dumps( # pylint: disable=too-many-arguments @@ -236,16 +240,12 @@ def loads( :param object_hook: function that will be called to decode objects values :returns: A Python object deserialized from string """ - try: - return simplejson.loads( - obj, - encoding=encoding, - allow_nan=allow_nan, - object_hook=object_hook, - ) - except JSONDecodeError as ex: - logger.error("JSON is not valid %s", str(ex), exc_info=True) - raise + return simplejson.loads( + obj, + encoding=encoding, + allow_nan=allow_nan, + object_hook=object_hook, + ) def redact_sensitive(