Skip to content

Commit 700fc7d

Browse files
committed
untag without object_hook
1 parent c275573 commit 700fc7d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

CHANGES.rst

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Unreleased
55

66
- Correct type for ``path`` argument to ``send_file``. :issue:`5230`
77
- Fix a typo in an error message for the ``flask run --key`` option. :pr:`5344`
8+
- Session data is untagged without relying on the built-in ``json.loads``
9+
``object_hook``. This allows other JSON providers that don't implement that.
10+
:issue:`5381`
811

912

1013
Version 3.0.0

src/flask/json/tag.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,22 @@ def untag(self, value: dict[str, t.Any]) -> t.Any:
305305

306306
return self.tags[key].to_python(value[key])
307307

308+
def _untag_scan(self, value: t.Any) -> t.Any:
309+
if isinstance(value, dict):
310+
# untag each item recursively
311+
value = {k: self._untag_scan(v) for k, v in value.items()}
312+
# untag the dict itself
313+
value = self.untag(value)
314+
elif isinstance(value, list):
315+
# untag each item recursively
316+
value = [self._untag_scan(item) for item in value]
317+
318+
return value
319+
308320
def dumps(self, value: t.Any) -> str:
309321
"""Tag the value and dump it to a compact JSON string."""
310322
return dumps(self.tag(value), separators=(",", ":"))
311323

312324
def loads(self, value: str) -> t.Any:
313325
"""Load data from a JSON string and deserialized any tagged objects."""
314-
return loads(value, object_hook=self.untag)
326+
return self._untag_scan(loads(value))

0 commit comments

Comments
 (0)