Fix UNIQUE constraint crash when same --attachment passed twice#1417
Open
abhicris wants to merge 1 commit intosimonw:mainfrom
Open
Fix UNIQUE constraint crash when same --attachment passed twice#1417abhicris wants to merge 1 commit intosimonw:mainfrom
abhicris wants to merge 1 commit intosimonw:mainfrom
Conversation
`llm "..." --attachment file.pdf --attachment file.pdf` raised `sqlite3.IntegrityError: UNIQUE constraint failed: prompt_attachments.response_id, prompt_attachments.attachment_id` from `_BaseResponse.log_to_db()` because the composite primary key on `prompt_attachments` was `(response_id, attachment_id)`. The same issue existed historically on `prompt_fragments` and was fixed in migration m016 by extending the PK with the `order` column. This mirrors that fix for `prompt_attachments` via a new `m022_prompt_attachments_pk` migration, and adds a CLI-level regression test. Closes simonw#1354
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.
Closes #1354.
The bug
The
prompt_attachmentstable was created inm012with a composite PK of(response_id, attachment_id), so inserting the same attachment a second time against one response violates the constraint. The full prompt + model call runs fine; only the log step crashes, which means the user sees a traceback instead of output.The fix
This is the same bug that previously existed on
prompt_fragments, fixed inm016_fragments_table_pksby extending the PK with the per-rowordercolumn. This PR mirrors that fix with a new migration:log_to_db()already passes a distinctorderper attachment (enumerate(self.prompt.attachments)), so the logic side needs no change.Verification
IntegrityErroragainstmainat 1bfb96d.(response_id, attachment_id)rows with distinctorder.test_duplicate_attachment_logs_cleanlyintests/test_attachments.pyexercising the CLI path end-to-end.--- kcolbchain / Abhishek Krishna