fix: prevent JSONB double-encoding on methodology save #6

Merged
chaim merged 2 commits from fix/methodology-jsonb-double-encoding into main 2026-05-10 18:34:03 +00:00
2 changed files with 5 additions and 2 deletions
Showing only changes of commit 50649baeed - Show all commits

View File

@@ -123,7 +123,7 @@ SUMMARY_STRATEGIES = {
DISCUSSION_RULES: dict[str, list[str]] = { DISCUSSION_RULES: dict[str, list[str]] = {
"universal": [ "universal": [
"פרק הדיון = אסה רציפה. אין כותרות משנה (H2/H3). מעברים רק עם ביטויי מעבר טקסטואליים.", "פרק הדיון = מאסה רציפה. אין כותרות משנה (H2/H3). מעברים רק עם ביטויי מעבר טקסטואליים.",
"חריג יחיד לכותרות משנה: נושאים נפרדים לחלוטין (למשל: הקלה בגובה + התייחסות לטענות נוספות).", "חריג יחיד לכותרות משנה: נושאים נפרדים לחלוטין (למשל: הקלה בגובה + התייחסות לטענות נוספות).",
"טווח אורך סעיפים: 20 עד 600+ מילים. סעיף עם ציטוט מקיף = בלוק אחד שלם, לא שבירה לסעיפים קצרים.", "טווח אורך סעיפים: 20 עד 600+ מילים. סעיף עם ציטוט מקיף = בלוק אחד שלם, לא שבירה לסעיפים קצרים.",
], ],

View File

@@ -3095,11 +3095,14 @@ async def api_update_methodology(category: str, key: str, req: MethodologyUpdate
raise HTTPException(422, "content_checklists value must be a non-empty string") raise HTTPException(422, "content_checklists value must be a non-empty string")
pool = await db.get_pool() pool = await db.get_pool()
# Pass req.value directly — asyncpg serializes Python list/dict to JSONB.
# json.dumps() caused double-encoding: string passed to ::jsonb became a JSONB string,
# not a JSONB array, making the frontend spread it as individual chars.
await pool.execute( await pool.execute(
"INSERT INTO appeal_type_rules (id, appeal_type, rule_category, rule_key, rule_value) " "INSERT INTO appeal_type_rules (id, appeal_type, rule_category, rule_key, rule_value) "
"VALUES (gen_random_uuid(), '_global', $1, $2, $3::jsonb) " "VALUES (gen_random_uuid(), '_global', $1, $2, $3::jsonb) "
"ON CONFLICT (appeal_type, rule_category, rule_key) DO UPDATE SET rule_value = $3::jsonb", "ON CONFLICT (appeal_type, rule_category, rule_key) DO UPDATE SET rule_value = $3::jsonb",
category, key, json.dumps(req.value, ensure_ascii=False), category, key, req.value,
) )
return {"key": key, "value": req.value, "is_override": True} return {"key": key, "value": req.value, "is_override": True}