This commit is contained in:
2026-01-31 16:11:25 -08:00
parent c854f8c6a8
commit dcf16e0cc4
6 changed files with 112 additions and 43 deletions

View File

@@ -2,6 +2,7 @@ from __future__ import annotations
import sqlite3
import json
import ast
import threading
import os
from queue import Queue
@@ -396,6 +397,9 @@ def rows_to_config(rows) -> Dict[str, Any]:
# Conservative JSON parsing: only attempt to decode when the value
# looks like JSON (object/array/quoted string/true/false/null/number).
# If JSON decoding fails, also attempt Python literal parsing (e.g., single-quoted
# dict/list reprs) using ast.literal_eval as a safe fallback. If both
# attempts fail, use the raw string value.
parsed_val = val
try:
if isinstance(val, str):
@@ -409,14 +413,26 @@ def rows_to_config(rows) -> Dict[str, Any]:
try:
parsed_val = json.loads(val)
except Exception:
parsed_val = val
# Try parsing Python literal formats (single-quoted dicts/lists)
try:
parsed_val = ast.literal_eval(val)
debug(f"Parsed config value for key '{key}' using ast.literal_eval (non-JSON literal)")
except Exception:
parsed_val = val
else:
parsed_val = val
else:
try:
parsed_val = json.loads(val)
except Exception:
parsed_val = val
# Non-string values can sometimes be bytes or Python literals; try decoding when appropriate
try:
if isinstance(val, (bytes, bytearray)):
parsed_val = json.loads(val.decode('utf-8', errors='replace'))
else:
parsed_val = val
except Exception:
parsed_val = val
except Exception:
parsed_val = val