From 78b45f716abede09ba8c671372b8a4fcfe11ae52 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Wed, 8 Jun 2022 20:25:35 +0200 Subject: [PATCH] Bugfix for #2433 (LazyString is not JSON serializable if one of kepubify/ebook-convert/unrar is not installed) --- cps/debug_info.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cps/debug_info.py b/cps/debug_info.py index 64fda557..6cb30edb 100644 --- a/cps/debug_info.py +++ b/cps/debug_info.py @@ -22,6 +22,7 @@ import glob import zipfile import json from io import BytesIO +from flask_babel.speaklater import LazyString import os @@ -32,6 +33,12 @@ from .about import collect_stats log = logger.create() +class lazyEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, LazyString): + return str(obj) + # Let the base class default method raise the TypeError + return json.JSONEncoder.default(self, obj) def assemble_logfiles(file_name): log_list = sorted(glob.glob(file_name + '*'), reverse=True) @@ -58,8 +65,8 @@ def send_debug(): file_list.remove(element) memory_zip = BytesIO() with zipfile.ZipFile(memory_zip, 'w', compression=zipfile.ZIP_DEFLATED) as zf: - zf.writestr('settings.txt', json.dumps(config.toDict())) - zf.writestr('libs.txt', json.dumps(collect_stats())) + zf.writestr('settings.txt', json.dumps(config.toDict(), sort_keys=True, indent=2)) + zf.writestr('libs.txt', json.dumps(collect_stats(), sort_keys=True, indent=2, cls=lazyEncoder)) for fp in file_list: zf.write(fp, os.path.basename(fp)) memory_zip.seek(0)