fix: recognise frappe's LocalProxy when serializing
This commit is contained in:
parent
9930dd5444
commit
1c73999821
2 changed files with 10 additions and 8 deletions
|
|
@ -1,9 +1,9 @@
|
|||
from contextvars import ContextVar
|
||||
from typing import Any, Generic, TypeVar
|
||||
|
||||
from werkzeug.local import LocalProxy as _LocalProxy
|
||||
from werkzeug.local import LocalProxy as WerkzeugLocalProxy
|
||||
from werkzeug.local import _ProxyLookup
|
||||
from werkzeug.local import release_local as _release_local
|
||||
from werkzeug.local import release_local as release_werkzeug_local
|
||||
|
||||
_contextvar = ContextVar("frappe_local")
|
||||
|
||||
|
|
@ -61,10 +61,10 @@ class Local:
|
|||
|
||||
|
||||
class LocalProxy(Generic[T]):
|
||||
__slots__ = _LocalProxy.__slots__
|
||||
__init__ = _LocalProxy.__init__
|
||||
__slots__ = WerkzeugLocalProxy.__slots__
|
||||
__init__ = WerkzeugLocalProxy.__init__
|
||||
|
||||
for attr, val in vars(_LocalProxy).items():
|
||||
for attr, val in vars(WerkzeugLocalProxy).items():
|
||||
if attr == "__getattr__" or not isinstance(val, _ProxyLookup):
|
||||
continue
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ def release_local(local):
|
|||
_contextvar.set({})
|
||||
return
|
||||
|
||||
_release_local(local)
|
||||
release_werkzeug_local(local)
|
||||
|
||||
|
||||
# _local_attributes = frozenset(attr for attr in dir(Local))
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ from urllib.parse import quote
|
|||
|
||||
import werkzeug.utils
|
||||
from werkzeug.exceptions import Forbidden, NotFound
|
||||
from werkzeug.local import LocalProxy
|
||||
from werkzeug.wrappers import Response
|
||||
from werkzeug.wsgi import wrap_file
|
||||
|
||||
|
|
@ -25,10 +24,13 @@ import frappe.utils
|
|||
from frappe import _
|
||||
from frappe.core.doctype.access_log.access_log import make_access_log
|
||||
from frappe.utils import format_timedelta
|
||||
from frappe.utils.local import LocalProxy, WerkzeugLocalProxy
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from frappe.core.doctype.file.file import File
|
||||
|
||||
LocalProxyType = LocalProxy | WerkzeugLocalProxy
|
||||
|
||||
|
||||
def report_error(status_code):
|
||||
"""Build error. Show traceback in developer mode"""
|
||||
|
|
@ -222,7 +224,7 @@ def json_handler(obj):
|
|||
elif isinstance(obj, decimal.Decimal):
|
||||
return float(obj)
|
||||
|
||||
elif isinstance(obj, LocalProxy):
|
||||
elif isinstance(obj, LocalProxyType):
|
||||
return str(obj)
|
||||
|
||||
elif hasattr(obj, "__json__"):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue