From 222a3cb1ff76677e977b91a85f4c8a1733ff7d49 Mon Sep 17 00:00:00 2001 From: umsangdon Date: Tue, 6 Oct 2026 15:27:32 +0900 Subject: [PATCH] =?UTF-8?q?fix(dashboard):=2054-44c=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=20=EC=B7=A8=ED=96=A5=20=EC=A0=80=EC=9E=A5=20=EB=95=8C=20?= =?UTF-8?q?=EC=A7=80=EC=9B=8C=EC=A7=84=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20id=20=ED=82=A4=20=EB=B2=84=EB=A6=BC=20=E2=80=94=20?= =?UTF-8?q?=EB=B8=8C=EB=9D=BC=EC=9A=B0=EC=A0=80=20=EC=98=9B=20=EC=82=AC?= =?UTF-8?q?=EB=B3=B8=EC=9D=98=20=EC=9E=AC=EC=98=A4=EC=97=BC=20=EB=A7=89?= =?UTF-8?q?=EC=9D=8C=20=C2=B7=20=EC=8B=9C=ED=97=98=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UoSr2sqvYtBf1dtQdus88s --- B01_Dashboard/B01_Dashboard_Repository.py | 16 ++++- .../tester/test_b01_ui_prefs_dead_project.py | 70 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 resources/tester/test_b01_ui_prefs_dead_project.py diff --git a/B01_Dashboard/B01_Dashboard_Repository.py b/B01_Dashboard/B01_Dashboard_Repository.py index 658c042fb..8907556f1 100644 --- a/B01_Dashboard/B01_Dashboard_Repository.py +++ b/B01_Dashboard/B01_Dashboard_Repository.py @@ -3,6 +3,7 @@ from __future__ import annotations import json +import re import shutil from datetime import datetime, timedelta from typing import Any @@ -547,10 +548,23 @@ async def get_user_ui_prefs(user_id: int) -> dict[str, Any]: return raw if isinstance(raw, dict) else {} +_UUID_IN_KEY = re.compile(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}") + + async def save_user_ui_prefs(user_id: int, prefs: dict[str, Any]) -> None: - """화면 취향을 통째로 덮어쓴다 — 사용자당 한 줄.""" + """화면 취향을 통째로 덮어쓴다 — 사용자당 한 줄. + + 지워진 프로젝트 id 가 박힌 키는 버림 — 브라우저 사본이 옛 키를 다시 올리지 못하게. + """ pool = get_db_pool() async with pool.acquire() as connection, connection.cursor() as cursor: + keyed = {key: m.group(0) for key in prefs if (m := _UUID_IN_KEY.search(key))} + if keyed: + ids = sorted(set(keyed.values())) + holders = ", ".join(["%s"] * len(ids)) + await cursor.execute(f"SELECT id FROM projects WHERE id IN ({holders})", ids) + live = {row[0] for row in await cursor.fetchall()} + prefs = {k: v for k, v in prefs.items() if k not in keyed or keyed[k] in live} await cursor.execute( """INSERT INTO user_ui_prefs (user_id, prefs) VALUES (%s, %s) ON DUPLICATE KEY UPDATE prefs = VALUES(prefs)""", diff --git a/resources/tester/test_b01_ui_prefs_dead_project.py b/resources/tester/test_b01_ui_prefs_dead_project.py new file mode 100644 index 000000000..c1e1e98f5 --- /dev/null +++ b/resources/tester/test_b01_ui_prefs_dead_project.py @@ -0,0 +1,70 @@ +"""화면 취향 저장 — 지워진 프로젝트 id 가 박힌 키는 버림 · 나머지 키는 그대로.""" + +import asyncio +import json + +import B01_Dashboard.B01_Dashboard_Repository as repo + +LIVE = "226fc805-26c8-4f5a-9956-bacb200e10a5" +DEAD = "936be972-11bc-46c2-8bf3-b15d8de7df0d" + + +class _Cursor: + def __init__(self, store): + self.store = store + self.rows = [] + + async def __aenter__(self): + return self + + async def __aexit__(self, *_): + return False + + async def execute(self, sql, args): + if sql.startswith("SELECT id FROM projects"): + self.rows = [(i,) for i in args if i == LIVE] + else: + self.store["saved"] = json.loads(args[1]) + + async def fetchall(self): + return self.rows + + +class _Conn: + def __init__(self, store): + self.store = store + + async def __aenter__(self): + return self + + async def __aexit__(self, *_): + return False + + def cursor(self): + return _Cursor(self.store) + + async def commit(self): + pass + + +class _Pool: + def __init__(self, store): + self.store = store + + def acquire(self): + return _Conn(self.store) + + +def test_dead_project_keys_dropped(monkeypatch): + store = {} + monkeypatch.setattr(repo, "get_db_pool", lambda: _Pool(store)) + prefs = { + f"aislo:pref:routeedit-view:{LIVE}": "a", + f"aislo:pref:routeedit-view:{DEAD}": "b", + "aislo:pref:table-open": "true", + } + asyncio.run(repo.save_user_ui_prefs(3, prefs)) + assert store["saved"] == { + f"aislo:pref:routeedit-view:{LIVE}": "a", + "aislo:pref:table-open": "true", + }