comms: fix guest renamer db sql quoting

This commit is contained in:
Brad Stein 2026-01-08 12:03:53 -03:00
parent 831f368493
commit d8c3bb2f1b

View File

@ -271,13 +271,13 @@ spec:
with conn.cursor() as cur:
cur.execute(
"SELECT name FROM users WHERE name ~ %s",
(f\"^@\\\\d+:{SERVER_NAME}$\",),
(f"^@\\d+:{SERVER_NAME}$",),
)
user_ids = [row[0] for row in cur.fetchall()]
if not user_ids:
return
cur.execute(
\"SELECT user_id, displayname FROM profiles WHERE user_id = ANY(%s)\",
"SELECT user_id, displayname FROM profiles WHERE user_id = ANY(%s)",
(user_ids,),
)
profiles = {row[0]: row[1] for row in cur.fetchall()}
@ -287,7 +287,7 @@ spec:
continue
new = None
for _ in range(30):
candidate = f\"{random.choice(ADJ)}-{random.choice(NOUN)}\"
candidate = f"{random.choice(ADJ)}-{random.choice(NOUN)}"
if candidate not in existing_names:
new = candidate
existing_names.add(candidate)
@ -295,7 +295,7 @@ spec:
if not new:
continue
cur.execute(
\"INSERT INTO profiles (user_id, displayname) VALUES (%s, %s) ON CONFLICT (user_id) DO UPDATE SET displayname = EXCLUDED.displayname\",
"INSERT INTO profiles (user_id, displayname) VALUES (%s, %s) ON CONFLICT (user_id) DO UPDATE SET displayname = EXCLUDED.displayname",
(user_id, new),
)
finally: