fix(sqlite): prevent FK constraint failure on batch create (GH#956)

Add checkForExistingIDs check to transaction-based batch creation
(sqliteTxStorage.CreateIssues) before calling insertIssues. This
prevents INSERT OR IGNORE from silently skipping duplicate IDs,
which would cause FK constraint failures when recording events
for issues that weren't actually inserted.

Also fixes unrelated test bug: renamed parseCommaSeparated to
parseCommaSeparatedList in validators_test.go.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
ruby
2026-01-10 20:58:06 -08:00
committed by Steve Yegge
parent 1ff8932468
commit 5605e590a3
2 changed files with 97 additions and 0 deletions

View File

@@ -296,6 +296,13 @@ func (t *sqliteTxStorage) CreateIssues(ctx context.Context, issues []*types.Issu
seenIDs[issue.ID] = true
}
// GH#956: Check for conflicts with existing IDs in database before inserting.
// This prevents INSERT OR IGNORE from silently skipping duplicates, which would
// cause FK constraint failures when recording events for non-inserted issues.
if err := checkForExistingIDs(ctx, t.conn, issues); err != nil {
return err
}
// Insert all issues
if err := insertIssues(ctx, t.conn, issues); err != nil {
return fmt.Errorf("failed to insert issues: %w", err)