Repository navigation
fix(sync): never import sheet rows into a userless group (Refs #184) - #246
Merged
Merged
Conversation
|
🔁 PR closed. Stage bot switched back to |
alex-mextner
force-pushed
the
fix-sync-import-user
branch
from
November 7, 2026 08:37
3cd809a to
3391817
Compare
3 tasks
importExpensesFromSheet fell back to user_id 1 when the group had no users. users.id is global and the FK does not check group_id, so cron year-recovery and /reconnect could hand imported expenses to another group's user. Mirror of the fixed /sync pattern: no fallback id; when the group has no user the rows are skipped and the count returned (SheetImportResult) so /reconnect reports «Таблица → БД: пропущено N строк — в группе нет ни одного участника» (never the misleading «синхронизированы» alongside) and cron logs a warn.
alex-mextner
force-pushed
the
fix-sync-import-user
branch
from
November 7, 2026 09:24
3391817 to
e4cac78
Compare
Closed
2 tasks done
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.
Что было
importExpensesFromSheet(src/bot/commands/sync.ts:414) при импорте расходов из Google Sheet брал владельца строк какusers[0]?.id ?? 1. Если у группы нет ни одного пользователя (users), фолбэк писалuser_id: 1. Ноusers.id— глобальный счётчик, и FK наexpenses.user_idне проверяетgroup_id: строки доставались пользователю другой группы.Пути, куда это стреляло: годовое восстановление по крону (
src/bot/cron.ts) и/reconnect(src/bot/commands/reconnect.ts).Фикс
Симметрично уже исправленному
/sync-пути (applyNewRow, sync.ts:220): фолбэк удалён — если у группы нет пользователя, импорт пропускается сlogger.warn([SYNC] Sheet import skipped: the group has no user to own the rows) и возвращается 0. Ни одна строка не пишется без same-group владельца.Тест
sync-expenses.test.ts— «a userless group imports nothing, never rows owned by another group's user 1»: создаётся другая группа с пользователемid=1, импорт в группу без пользователей должен вернуть 0 и не записать ни одного расхода (red-verified на старом коде).Gates:
server-run -- bun run test— 253 файла / 6071 тест, 0 fail; type-check ✅; lint ✅. Машинное ревью: чисто.Refs #184