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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user