Repository navigation
fix(admin,db): fix /kill and /unban crashes, persist bans, harden add_user - #119
Merged
Merged
Conversation
…_user - /kill without a chat_id replied with a usage hint and then crashed with an IndexError, because it didn't return. - /unban for a user who wasn't banned raised a KeyError. Use set.discard instead of set.remove. - Banning a user who has no row in the users table only added them to the in-memory set, so the ban was lost on restart. Insert a users row first if it doesn't exist. - add_user swallowed IntegrityErrors without rolling back, leaving a half written user in the open transaction. Users without a Telegram language_code violated the NOT NULL constraint of chats.lang_id, and users whose chat row already existed (after /language) hit the primary key. Default the language to "en", ignore an existing chat row and roll back on remaining errors. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KouGQtM6VBedfBdNr8WFX5
d-Rickyy-b
force-pushed
the
claude/project-thread-gbpez2-admin-db
branch
from
October 8, 2026 21:32
22aa4ae to
5479be6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Rico · project thread
Before:
/killwithout a chat id replied "Please provide a chat_id!" and then crashed with anIndexError./unban <id>for a user who wasn't banned crashed with aKeyError./ban <id>for someone who never used the bot only worked until the next restart.language_code, or one who had used/languagebefore/start, hit anIntegrityErrorinadd_user. The error was swallowed and left a half-written user in the open transaction, which the next unrelated commit then committed.After:
/killjust shows the usage hint. Unbanning a user who isn't banned is a no-op. Bans of unknown users are stored in the database. New users are always stored with a valid chat row.How:
kill_game_cmdnow returns after the usage hint.unban_userusesset.discardinstead ofset.remove.ban_userrunsINSERT OR IGNOREfor the users row before settingbanned=1._add_userdefaults the language to"en", usesINSERT OR IGNOREfor the chats row (an existing language choice is kept), and rolls back on any remainingIntegrityError.New tests are in
database/tests/database_test.py. They use random user ids and clean up after themselves. Three of them fail on master and all four pass with this change.🤖 Generated with Claude Code
https://claude.ai/code/session_01KouGQtM6VBedfBdNr8WFX5
Generated by Claude Code