Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-759] [ENG-1104] patch json.dumps to handle __wrapped__ objects #4166

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dataclasses
import functools
import inspect
import json
import pickle
import sys
import uuid
Expand Down Expand Up @@ -3715,6 +3716,29 @@ def serialize_mutable_proxy(mp: MutableProxy):
return mp.__wrapped__


_orig_json_JSONEncoder_default = json.JSONEncoder.default


def _json_JSONEncoder_default_wrapper(self: json.JSONEncoder, o: Any) -> Any:
"""Wrap JSONEncoder.default to handle MutableProxy objects.

Args:
self: the JSONEncoder instance.
o: the object to serialize.

Returns:
A JSON-able object.
"""
try:
return o.__wrapped__
except AttributeError:
pass
return _orig_json_JSONEncoder_default(self, o)


json.JSONEncoder.default = _json_JSONEncoder_default_wrapper


class ImmutableMutableProxy(MutableProxy):
"""A proxy for a mutable object that tracks changes.

Expand Down
Loading