koishijs / koishi

Cross-platform chatbot framework made with love
https://koishi.chat
MIT License
4.5k stars 247 forks source link

Bug: ER_BAD_NULL_ERROR: Column 'pid' cannot be null #1056

Closed Ice-Hazymoon closed 1 year ago

Ice-Hazymoon commented 1 year ago

Describe the bug

无法在 telegram/callback-query 事件中调用 session.execute

ctx.on("telegram/callback-query", async (session) => {
        if (session.telegram.callback_query) {
            const callbackQuery = session.telegram.callback_query;
            const { data } = callbackQuery; // help
            return await session.execute(data);
        }
});

Steps to reproduce

rt

Expected behavior

rt

Screenshots

No response

Versions

Additional context

No response

Ice-Hazymoon commented 1 year ago
2023-04-01 01:06:34 [W] mysql INSERT INTO `binding` (`aid`, `bid`, `pid`, `platform`) VALUES (72, 72, NULL, 'telegram')
2023-04-01 01:06:34 [W] app ER_BAD_NULL_ERROR: Column 'pid' cannot be null
                            at MySQLDriver.query (E:\Project\bott-ai-bot\node_modules\@minatojs\driver-mysql\src\index.ts:306:19)
                            at MySQLDriver.create (E:\Project\bott-ai-bot\node_modules\@minatojs\driver-mysql\src\index.ts:450:31)
                            at Executable.execute (E:\Project\bott-ai-bot\node_modules\@minatojs\core\src\selection.ts:98:40)
                            at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
                            at DatabaseService.createUser (E:\Project\bott-ai-bot\node_modules\@koishijs\core\src\database.ts:138:5)
                            at Session2.observeUser (E:\Project\bott-ai-bot\node_modules\@koishijs\core\src\session.ts:251:18)
                            at Session2.execute (E:\Project\bott-ai-bot\node_modules\@koishijs\core\src\session.ts:376:7)
                            at Session2.<anonymous> (e:\Project\bott-ai-bot\external\init-menu\src\index.ts:216:20) 
shigma commented 1 year ago

直接分析错误日志可得:该 session 没有 userId,不能直接 execute。

可能可以在 adapter 中修复。

Ice-Hazymoon commented 1 year ago

谢谢,貌似 session 很多功能都无法在该事件中使用,包括 .send,只能通过 await session.telegram 来发送消息 这个 issue 我是留着还是关了

shigma commented 1 year ago

那当然是留着。确认解决或者确认不会解决之前都留着。

Ice-Hazymoon commented 1 year ago

我还可以使用其他方式调用 execute 吗

shigma commented 1 year ago

只能在 session 调用,等修吧