mirror of
https://github.com/zvx-echo6/central.git
synced 2026-05-22 02:24:38 +02:00
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:
parent
dec8ce8545
commit
0f127399b3
2 changed files with 112 additions and 13 deletions
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue