Error viewing issue, http 500 #338

Closed
opened 2025-11-02 03:19:11 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @jeppech on GitHub (Feb 10, 2017).

Originally assigned to: @lunny on GitHub.

I'm getting a 500 when accessing an issue. This happens apparently because of a missing label.
I'm using v/ 1.0.0+244-ga6751cec

It seem's, that this issue had a label, which has been deleted later on, but not it's relation to the issue.

2017/02/10 19:03:22 [...outers/repo/issue.go:612 ViewIssue()] [E] LoadLabel: label does not exist [label_id: 20, repo_id: 0]
2017/02/10 19:03:22 [D] Template: status/500
Originally created by @jeppech on GitHub (Feb 10, 2017). Originally assigned to: @lunny on GitHub. I'm getting a 500 when accessing an issue. This happens apparently because of a missing label. I'm using v/ 1.0.0+244-ga6751cec It seem's, that this issue had a label, which has been deleted later on, but not it's relation to the issue. ``` 2017/02/10 19:03:22 [...outers/repo/issue.go:612 ViewIssue()] [E] LoadLabel: label does not exist [label_id: 20, repo_id: 0] 2017/02/10 19:03:22 [D] Template: status/500 ```
GiteaMirror added the type/bug label 2025-11-02 03:19:11 -06:00
Author
Owner

@jeppech commented on GitHub (Feb 10, 2017):

Here's some data from my db:

sqlite> select count(*) from label where id = 20;
count(*)
----------
0

sqlite> select count(*) from repository where id = 0;
count(*)
----------
0

So something is definitely up, I just noticed that the repo_id is supposedly 0.
I realised repo_id is 0, because it's not parsed to the error model, https://github.com/go-gitea/gitea/blob/master/models/issue_comment.go#L215-L219

This is the concerned issues, with their labels

sqlite> SELECT
   ...>     iss.id, iss.repo_id, iss.`index`,
   ...>     isl.label_id,
   ...>     lab.name, lab.num_issues
   ...> FROM issue iss
   ...> LEFT JOIN issue_label isl
   ...>     ON isl.issue_id = iss.id
   ...> LEFT JOIN label lab
   ...>     ON lab.id = isl.label_id
   ...> WHERE iss.`index`
   ...>     IN (102,101,98);
id          repo_id     index       label_id    name             num_issues
----------  ----------  ----------  ----------  ---------------  ----------
167         15          98          75          priority/medium  8
170         15          101         75          priority/medium  8
171         15          102         75          priority/medium  8

I cannot fint any label_id = 20, anywhere in the database.

@jeppech commented on GitHub (Feb 10, 2017): Here's some data from my db: ``` sqlite> select count(*) from label where id = 20; count(*) ---------- 0 sqlite> select count(*) from repository where id = 0; count(*) ---------- 0 ``` ~So something is definitely up, I just noticed that the repo_id is supposedly 0.~ I realised repo_id is 0, because it's not parsed to the error model, https://github.com/go-gitea/gitea/blob/master/models/issue_comment.go#L215-L219 This is the concerned issues, with their labels ``` sqlite> SELECT ...> iss.id, iss.repo_id, iss.`index`, ...> isl.label_id, ...> lab.name, lab.num_issues ...> FROM issue iss ...> LEFT JOIN issue_label isl ...> ON isl.issue_id = iss.id ...> LEFT JOIN label lab ...> ON lab.id = isl.label_id ...> WHERE iss.`index` ...> IN (102,101,98); id repo_id index label_id name num_issues ---------- ---------- ---------- ---------- --------------- ---------- 167 15 98 75 priority/medium 8 170 15 101 75 priority/medium 8 171 15 102 75 priority/medium 8 ``` I cannot fint any label_id = 20, anywhere in the database.
Author
Owner

@jeppech commented on GitHub (Feb 10, 2017):

Okay, so the problem seems to be with the feature, of tracking labels by @lunny. If a label that has been used in an issue, is deleted afterwards. It throws.

And I'm guessing it's due to this
https://github.com/go-gitea/gitea/blob/master/routers/repo/issue.go#L610-L614

Though, I'm still struggling to find out where label_id=20 originates.

Never the less, to replicate this:
Create an issue, and add a label to it.
Delete the label, from the label management page.
Viewing issue, throws 500

@jeppech commented on GitHub (Feb 10, 2017): Okay, so the problem seems to be with the feature, of tracking labels by @lunny. If a label that has been used in an issue, is deleted afterwards. It throws. And I'm guessing it's due to this https://github.com/go-gitea/gitea/blob/master/routers/repo/issue.go#L610-L614 Though, I'm still struggling to find out where label_id=20 originates. Never the less, to replicate this: Create an issue, and add a label to it. Delete the label, from the label management page. Viewing issue, throws 500
Author
Owner

@jeppech commented on GitHub (Feb 10, 2017):

I've found the sinner!

sqlite> SELECT
   ...>     iss.id,
   ...>     iss.`index`,
   ...>     cmt.label_id
   ...> FROM issue iss
   ...> LEFT JOIN comment cmt
   ...>     ON cmt.issue_id = iss.id
   ...> WHERE iss.`index`
   ...>     IN (102,101,98)
   ...> AND cmt.label_id = 20;
id          index       label_id
----------  ----------  ----------
167         98          20
170         101         20
171         102         20

The label_id is still in the comment table. So, when deleting labels, the related records in the comment should be deleted as well.

Also note, this error also occurs for milestones!

@jeppech commented on GitHub (Feb 10, 2017): I've found the sinner! ``` sqlite> SELECT ...> iss.id, ...> iss.`index`, ...> cmt.label_id ...> FROM issue iss ...> LEFT JOIN comment cmt ...> ON cmt.issue_id = iss.id ...> WHERE iss.`index` ...> IN (102,101,98) ...> AND cmt.label_id = 20; id index label_id ---------- ---------- ---------- 167 98 20 170 101 20 171 102 20 ``` The label_id is still in the `comment` table. So, when deleting labels, the related records in the comment should be deleted as well. **Also note, this error also occurs for milestones!**
Author
Owner

@lunny commented on GitHub (Feb 11, 2017):

I will send a PR to fix this.

@lunny commented on GitHub (Feb 11, 2017): I will send a PR to fix this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#338