From ecfc188388147f3dd0d7b81756b5175d03f9790e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 1 Oct 2025 05:59:48 +0000 Subject: [PATCH] Make ObjectSerializer handle all iterables including generators Co-authored-by: alexta69 <7450369+alexta69@users.noreply.github.com> --- app/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index b13ac9a..73132a7 100644 --- a/app/main.py +++ b/app/main.py @@ -115,10 +115,18 @@ config = Config() class ObjectSerializer(json.JSONEncoder): def default(self, obj): + # First try to use __dict__ for custom objects if hasattr(obj, '__dict__'): return obj.__dict__ - else: - return json.JSONEncoder.default(self, obj) + # Convert iterables (generators, dict_items, etc.) to lists + # Exclude strings and bytes which are also iterable + elif hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes)): + try: + return list(obj) + except: + pass + # Fall back to default behavior + return json.JSONEncoder.default(self, obj) serializer = ObjectSerializer() app = web.Application()