gongzhiyongandClaude Sonnet 4.6 c54e2be5c4 fix(backend): validate conversation_id FK before inserting attachment
When the frontend passes a conversation_id that does not exist in the
conversations table (e.g. new conversation before first message, or
invalid ID), the INSERT into attachments failed with
ForeignKeyViolationError.

Now upload_attachment checks session.get(Conversation, conversation_id)
before inserting. If the conversation does not exist, conversation_id is
set to None and the attachment is stored as unlinked (blob path uses
_unlinked/ prefix). This avoids the FK constraint error while keeping
the file safely uploaded.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 21:02:03 +08:00
S
Description
No description provided
14 MiB
Languages
TypeScript 89.2%
CSS 4.3%
Makefile 2.9%
JavaScript 2.5%
Dockerfile 0.5%
Other 0.6%