Skip to content

Commit 817db51

Browse files
committed
[FIX] orjson: serialize namedtuples
As opposed to json lib, orjson cannot serialize namedtuple objects 'TypeError: Type is not JSON serializable' Part-of: #155 Related: odoo/upgrade#6662 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent fc0df25 commit 817db51

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/util/json.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def load(fp):
1616
else:
1717

1818
def dumps(value, sort_keys=False):
19+
if isinstance(value, tuple):
20+
# downcast namedtuples
21+
value = tuple(value)
22+
1923
option = orjson.OPT_NON_STR_KEYS
2024
if sort_keys:
2125
option |= orjson.OPT_SORT_KEYS

0 commit comments

Comments
 (0)