From 6f3b550e889c4494d65f42f500845fc29364d902 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Thu, 31 Oct 2024 13:52:00 -0700 Subject: [PATCH] Skip default fallback logic when `cls` is specified `cls` will provide its own default serialization mechanism, passing a `cls` Encoder class is now also a way to opt-out of our patching shenanigans and just use your own code. This will work, provided the library doing the JSON encoding isn't also using their own custom class. --- reflex/state.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reflex/state.py b/reflex/state.py index 655639184..453e17e30 100644 --- a/reflex/state.py +++ b/reflex/state.py @@ -3729,7 +3729,8 @@ def _json_dumps_wrapper(*args, **kwargs): Returns: The JSON string. """ - _orig_default = kwargs.pop("default", None) + if "cls" not in kwargs: + _orig_default = kwargs.pop("default", None) def _default(obj): if _orig_default is not None: @@ -3743,7 +3744,8 @@ def _json_dumps_wrapper(*args, **kwargs): pass raise TypeError() - kwargs["default"] = _default + if "cls" not in kwargs: + kwargs["default"] = _default return _orig_json_dumps(*args, **kwargs)