Skip to content

Retrying the insert on issue fails, and masks the actual error #8302

Closed
@guillep2k

Description

@guillep2k
  • Gitea version (or commit ref): c6fb7fe

Description

The changes introduced in #7898 simply don't work, because if xorm.Session.Insert() returns any errors, the session becomes invalidated, so subsequent attempts fail with:

newIssue: pq: current transaction is aborted, commands ignored until end of transaction block

gitea/models/issue.go

Lines 1108 to 1122 in c6fb7fe

// There's no good way to identify a duplicate key error in database/sql; brute force some retries
dupIndexAttempts := issueMaxDupIndexAttempts
for {
_, err := e.SetExpr("`index`", "coalesce(MAX(`index`),0)+1").
Where("repo_id=?", opts.Issue.RepoID).
Insert(opts.Issue)
if err == nil {
break
}
dupIndexAttempts--
if dupIndexAttempts <= 0 {
return err
}
}

I'm sorry, after so many attempts to solve the potential duplicate index, we're back to square zero.

@lunny how would you like to handle this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions