Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] 图片上传成功但数据库没记录 #3019

Closed
fushes opened this issue Jun 24, 2024 · 3 comments
Closed

[Bug] 图片上传成功但数据库没记录 #3019

fushes opened this issue Jun 24, 2024 · 3 comments
Labels
🐛 Bug Something isn't working | 缺陷

Comments

@fushes
Copy link

fushes commented Jun 24, 2024

📦 Environment

Docker

📌 Version

1.1.7

💻 Operating System

Windows

🌐 Browser

Edge

🐛 Bug Description

自己构建镜像了数据库版,配置好s3后也能够传图片,但是在发送消息的时候会报错,经过排查数据库发现file表中并没有上传文件的记录,导致files_to_messages表中的file_id字段外键约束报错,我取消外键约束后发现可以正常发送并且AI正常读取图片。通过阅读代码发现问题应该出现在const result = await uploadService.uploadFile(fileItem); const data = await fileService.createFile(result);是否考虑在中间几个判断:// 校验上传结果 if (!uploadResult || !uploadResult.fileId) { throw new Error('文件上传失败:' + uploadResult?.errorMessage); }希望开发大大能复现这个bug

📷 Recurrence Steps

No response

🚦 Expected Behavior

No response

📝 Additional Information

{"level":30,"time":1719257750186,"pid":1,"hostname":"f5b2310fb12f","msg":"Error in tRPC handler (lambda) on path: message.createMessage, type: mutation"}
error: insert or update on table "files_to_messages" violates foreign key constraint "files_to_messages_file_id_files_id_fk"
at /app/node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js:526:17
... 8 lines matching cause stack trace ...
at async r (/app/.next/server/chunks/89824.js:1:2169) {
code: 'INTERNAL_SERVER_ERROR',
name: 'TRPCError',
[cause]: error: insert or update on table "files_to_messages" violates foreign key constraint "files_to_messages_file_id_files_id_fk"
at /app/node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js:526:17
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /app/.next/server/app/trpc/lambda/[trpc]/route.js:4:12341
at async g.transaction (/app/.next/server/chunks/88811.js:27:9146)
at async /app/.next/server/app/trpc/lambda/[trpc]/route.js:4:14989
at async h.middlewares (/app/.next/server/chunks/89824.js:1:1895)
at async r (/app/.next/server/chunks/89824.js:1:2169)
at async r (/app/.next/server/chunks/89824.js:1:2169)
at async r (/app/.next/server/chunks/89824.js:1:2169)
at async r (/app/.next/server/chunks/89824.js:1:2169) {
length: 316,
severity: 'ERROR',
code: '23503',
detail: 'Key (file_id)=(file-VVoijxPw) is not present in table "files".',
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: 'public',
table: 'files_to_messages',
column: undefined,
dataType: undefined,
constraint: 'files_to_messages_file_id_files_id_fk',
file: 'ri_triggers.c',
line: '2608',
routine: 'ri_ReportViolation'
}
}

@fushes fushes added the 🐛 Bug Something isn't working | 缺陷 label Jun 24, 2024
@lobehubbot
Copy link
Member

👀 @fushes

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible.
Please make sure you have given us as much context as possible.
非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


📦 Environment

Docker

📌 Version

1.1.7

💻 Operating System

Windows

🌐 Browser

Edge

🐛 Bug Description

I built a mirrored database version myself. After configuring S3, I can also upload pictures. However, an error will be reported when sending a message. After checking the database, I found that there is no record of uploaded files in the file table, resulting in an error in the foreign key constraint of the file_id field in the files_to_messages table. , I canceled the foreign key constraint and found that it could be sent normally and the AI ​​could read the image normally. By reading the code, I found that the problem should occur in const result = await uploadService.uploadFile(fileItem); const data = await fileService.createFile(result);Whether to consider several judgments in the middle://Verify the upload result if (!uploadResult || !uploadResult.fileId) { throw new Error('File upload failed: ' + uploadResult?.errorMessage); }I hope developers can reproduce this bug

📷 Recurrence Steps

No response

🚦 Expected Behavior

No response

📝 Additional Information

{"level":30,"time":1719257750186,"pid":1,"hostname":"f5b2310fb12f","msg":"Error in tRPC handler (lambda) on path: message.createMessage, type: mutation" }
error: insert or update on table "files_to_messages" violates foreign key constraint "files_to_messages_file_id_files_id_fk"
at /app/node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js:526:17
... 8 lines matching cause stack trace ...
at async r (/app/.next/server/chunks/89824.js:1:2169) {
code: 'INTERNAL_SERVER_ERROR',
name: 'TRPCError',
[cause]: error: insert or update on table "files_to_messages" violates foreign key constraint "files_to_messages_file_id_files_id_fk"
at /app/node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js:526:17
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /app/.next/server/app/trpc/lambda/[trpc]/route.js:4:12341
at async g.transaction (/app/.next/server/chunks/88811.js:27:9146)
at async /app/.next/server/app/trpc/lambda/[trpc]/route.js:4:14989
at async h.middlewares (/app/.next/server/chunks/89824.js:1:1895)
at async r (/app/.next/server/chunks/89824.js:1:2169)
at async r (/app/.next/server/chunks/89824.js:1:2169)
at async r (/app/.next/server/chunks/89824.js:1:2169)
at async r (/app/.next/server/chunks/89824.js:1:2169) {
length: 316,
severity: 'ERROR',
code: '23503',
detail: 'Key (file_id)=(file-VVoijxPw) is not present in table "files".',
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: 'public',
table: 'files_to_messages',
column: undefined,
dataType: undefined,
constraint: 'files_to_messages_file_id_files_id_fk',
file: 'ri_triggers.c',
line: '2608',
routine: 'ri_ReportViolation'
}
}

@fushes fushes closed this as completed Jun 29, 2024
@lobehubbot
Copy link
Member

@fushes

This issue is closed, If you have any questions, you can comment and reply.
此问题已经关闭。如果您有任何问题,可以留言并回复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working | 缺陷
Projects
Status: Done
Development

No branches or pull requests

2 participants