ソースを参照

Fix 500 when a comment was deleted which has a notification (#17550)

* Fix 500 when a comment was deleted which has a notification

* Tolerate missing Comment in other places too

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
tags/v1.16.0-rc1
Lunny Xiao 2年前
コミット
43bbc54783
コミッターのメールアドレスに関連付けられたアカウントが存在しません
3個のファイルの変更11行の追加5行の削除
  1. 8
    2
      models/notification.go
  2. 1
    1
      routers/api/v1/notify/repo.go
  3. 2
    2
      routers/api/v1/notify/threads.go

+ 8
- 2
models/notification.go ファイルの表示

@@ -434,7 +434,13 @@ func (n *Notification) loadComment(e db.Engine) (err error) {
if n.Comment == nil && n.CommentID != 0 {
n.Comment, err = getCommentByID(e, n.CommentID)
if err != nil {
return fmt.Errorf("GetCommentByID [%d] for issue ID [%d]: %v", n.CommentID, n.IssueID, err)
if IsErrCommentNotExist(err) {
return ErrCommentNotExist{
ID: n.CommentID,
IssueID: n.IssueID,
}
}
return err
}
}
return nil
@@ -488,7 +494,7 @@ type NotificationList []*Notification
func (nl NotificationList) LoadAttributes() (err error) {
for i := 0; i < len(nl); i++ {
err = nl[i].LoadAttributes()
if err != nil {
if err != nil && !IsErrCommentNotExist(err) {
return
}
}

+ 1
- 1
routers/api/v1/notify/repo.go ファイルの表示

@@ -121,7 +121,7 @@ func ListRepoNotifications(ctx *context.APIContext) {
return
}
err = nl.LoadAttributes()
if err != nil {
if err != nil && !models.IsErrCommentNotExist(err) {
ctx.InternalServerError(err)
return
}

+ 2
- 2
routers/api/v1/notify/threads.go ファイルの表示

@@ -40,7 +40,7 @@ func GetThread(ctx *context.APIContext) {
if n == nil {
return
}
if err := n.LoadAttributes(); err != nil {
if err := n.LoadAttributes(); err != nil && !models.IsErrCommentNotExist(err) {
ctx.InternalServerError(err)
return
}
@@ -92,7 +92,7 @@ func ReadThread(ctx *context.APIContext) {
ctx.InternalServerError(err)
return
}
if err = notif.LoadAttributes(); err != nil {
if err = notif.LoadAttributes(); err != nil && !models.IsErrCommentNotExist(err) {
ctx.InternalServerError(err)
return
}

読み込み中…
キャンセル
保存