fix(gui): remove JSONB double-encoding in adapter updates

The GUI pool has init=_setup_json_codec registered, which makes asyncpg
auto-serialize Python dicts to JSONB. Calling json.dumps() on a dict
before passing it to asyncpg double-encodes - the value gets stored as
a JSON-encoded string rather than a JSON object.

Changes:
- Remove json.dumps() from UPDATE statement in adapters_edit_submit
- Remove defensive isinstance(settings, str) checks that masked the bug
- Add regression tests to verify settings is passed as dict, not string

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ubuntu 2026-05-17 21:33:48 +00:00
commit 0f127399b3
2 changed files with 112 additions and 13 deletions

View file

@ -578,10 +578,7 @@ async def adapters_list(
adapters = []
for row in rows:
# asyncpg auto-deserializes jsonb to dict
settings = row["settings"] if row["settings"] else {}
if isinstance(settings, str):
settings = json.loads(settings)
settings = row["settings"] or {}
adapters.append({
"name": row["name"],
"enabled": row["enabled"],
@ -634,10 +631,7 @@ async def adapters_edit_form(
"SELECT alias FROM config.api_keys ORDER BY alias"
)
# asyncpg auto-deserializes jsonb to dict
settings = row["settings"] if row["settings"] else {}
if isinstance(settings, str):
settings = json.loads(settings)
settings = row["settings"] or {}
adapter = {
"name": row["name"],
"enabled": row["enabled"],
@ -716,10 +710,7 @@ async def adapters_edit_submit(
if row is None:
return Response(status_code=404, content="Adapter not found")
# asyncpg auto-deserializes jsonb to dict
current_settings = row["settings"] if row["settings"] else {}
if isinstance(current_settings, str):
current_settings = json.loads(current_settings)
current_settings = row["settings"] or {}
new_settings = dict(current_settings)
# Adapter-specific validation and settings update
@ -826,7 +817,7 @@ async def adapters_edit_submit(
""",
enabled,
cadence_s,
json.dumps(new_settings),
new_settings,
name,
)