-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Locked out of the ability to comment on the code of a PR sometimes #12239
Comments
I seem to have something similar. After commenting for a while on the
I don't recall any comment being anything special other than containing some code snippets and a weblink. Now I cannot access that part of the PR anymore :-(.
|
To what review ID that comment was pointing to (other PR/repo)? |
I don't know, I was using the Later in the day, I decided to avoid the We have since downgraded 1.11.3 (the version we had before upgrading to 1.12.0/1), I've tried all the review / comment functionality and everything seems to work fine again. We upgraded simply by pulling the new docker image and starting it on top of our pre-existing gitea database. Is it possible the database from 1.11.3 are not compatible with 1.12.0/1? |
For our case, the comment should have been pointing at PR 35, internal review id 192 or something. I think, based on perusing the pgsql database a bit, that the review ID is actually set to 0 on the offending comment.
This is how most of our review comments are done as well.
We see this occasionally as well, usually when the code has changed between the time the PR was loaded and the comment was submitted, but we see it other times as well.
1.12.1 was the first version we installed and we are seeing the issue, so I think it's unlikely to be a db upgrade bug. |
Thanks, will try to reproduce |
having the same problem as well. I added several pieces of comments with
I am using Gitea 1.12.2, too. Windows Server 2008, MySQL. |
I can confirm that the issue exists on on Gitea 1.12.3. with sqlite. It worked after creation of the PR, but broke after 1 or 2 inline comments were added. So I guess there is an issue with rendering already existing comments? Also, one user noted that his comments were not visible at all in the beginning. Not sure if this is related or reproducible. |
Having the same issue, let me know if there is anything I can do to help debug this. |
I initially was wondering if this was some issue with a certain number of reviews but I just added >80 reviews to a PR on my test instance and it hasn't failed (albeit this is on master/1.13) Is anyone able to confirm that the bug is not present on master/try? I would guess that at least a temporary solution would involve monkey patching the template repo/diff/box.tmpl to prevent the NPE around line 152. |
Very stable to reproduce here: https://try.gitea.io/hardi/pull-request-test/pulls/1/files |
Cool that means it's definitely not just a 1.12 issue. It's really weird that I can't forcibly reproduce on my dev machine |
Thank you! I'll update the original post with this link. |
This is interesting - I can't replicate it on my dev box but if you look at the API you see an interesting finding:
[
{
"id": 226,
"user": {
"id": 0,
"login": "hardi",
"full_name": "",
"email": "testuseer@labfolder.com",
"avatar_url": "https://try.gitea.io/user/avatar/hardi/-1",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2019-02-11T07:23:04Z",
"username": "hardi"
},
"state": "COMMENT",
"body": "make change man",
"commit_id": "",
"stale": false,
"official": false,
"comments_count": 0,
"submitted_at": "2019-02-11T07:25:41Z",
"html_url": "https://try.gitea.io/hardi/pull-request-test/pulls/1#issuecomment-9975",
"pull_request_url": "https://try.gitea.io/hardi/pull-request-test/pulls/1"
},
...
] Vs a sort of equivalent:
[
{
"id": 78,
"user": {
"id": 1,
"login": "administrator",
"full_name": "",
"email": "administrator@example.com",
"avatar_url": "http://localhost/gitea/user/avatar/administrator/-1",
"language": "en-US",
"is_admin": true,
"last_login": "2020-07-31T09:58:07+01:00",
"created": "2020-02-15T13:21:17Z",
"username": "administrator"
},
"state": "COMMENT",
"body": "",
"commit_id": "25d641639d06ce48c88ec4142a9b0f6bcb45e813",
"stale": false,
"official": false,
"comments_count": 2,
"submitted_at": "2020-08-05T14:33:27+01:00",
"html_url": "http://localhost/gitea/administrator/pull-request-test/pulls/1#issuecomment-255",
"pull_request_url": "http://localhost/gitea/administrator/pull-request-test/pulls/1"
},
...
] Note the commit_id is empty on the broken try instance. |
We got this error as well in 1.12.1. Only few persons reported this to us, maybe the amount of people having this is greater than I am aware of. |
I think I've tracked this down -- To reproduce: 1: Comment on a specific line of a PR 2: Make a commit that changes the line and automatically marks the previous comments as outdated (per #9532) 3: Go back to files view which now doesn't show previous review 4: Leave a comment on the same line as previous See error above So this process causes new comments to be created with a reviewID of 0 which then triggers the NPE above because the comment will have no review loaded. Seems to be this bit: Lines 32 to 37 in 74bd969
Will see the previous comment that has been invalidated by a commit because it only looks to see if there is an existing comment at that line. Then here: Lines 40 to 54 in 74bd969
It leaves a comment with replyReviewID instead of trying to load the actual review and use that ID because it thinks one already exists and this is just a comment. Not sure, but replyReviewID appears to always be 0 from here: gitea/routers/repo/pull_review.go Lines 38 to 48 in 74bd969
(form.Reply) Perhaps this: Lines 265 to 268 in 74bd969
Should check for comment.invalidated as well? Not sure how this is supposed to work but that seems to be what causes the bug. Also would probably need something to either fix what will now be broken comments or change the template to ignore them and avoid this error... |
Here's a quick patch to prevent the NPE whilst we fix the underlying issue. From ff164dabec13c9c2d10593fc5ffcd0d316018ada Mon Sep 17 00:00:00 2001
From: Andrew Thornton <art27@cantab.net>
Date: Thu, 20 Aug 2020 17:50:35 +0100
Subject: [PATCH] Prevent NPE in template generation
Prevent the NPE in #12239 by assuming that a comment without a Review is
non-pending.
Related #12239
Signed-off-by: Andrew Thornton <art27@cantab.net>
---
templates/repo/diff/box.tmpl | 5 ++++-
templates/repo/diff/section_unified.tmpl | 5 ++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl
index 7338c1ee6..397356fe6 100644
--- a/templates/repo/diff/box.tmpl
+++ b/templates/repo/diff/box.tmpl
@@ -155,7 +155,10 @@
{{if gt (len $line.Comments) 0}}
{{$resolved := (index $line.Comments 0).IsResolved}}
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
- {{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
+ {{$isNotPending := false}}
+ {{if (index $line.Comments 0).Review}}
+ {{$isNotPending = (not (eq (index $line.Comments 0).Review.Type 0))}}
+ {{end}}
<tr class="add-code-comment">
<td class="lines-num"></td>
<td class="lines-type-marker"></td>
diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl
index 5f87a4176..2508c01fe 100644
--- a/templates/repo/diff/section_unified.tmpl
+++ b/templates/repo/diff/section_unified.tmpl
@@ -35,7 +35,10 @@
{{if gt (len $line.Comments) 0}}
{{$resolved := (index $line.Comments 0).IsResolved}}
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
- {{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
+ {{$isNotPending := false}}
+ {{if (index $line.Comments 0).Review}}
+ {{$isNotPending = (not (eq (index $line.Comments 0).Review.Type 0))}}
+ {{end}}
<tr>
<td colspan="2" class="lines-num"></td>
<td class="add-comment-left add-comment-right" colspan="2">
--
2.25.1 |
Hmm, If we turn this: Line 32 in 74bd969
to: if !isReview && replyReviewID != 0 { This will prevent the issue. Current suggested patchFrom 309fd941612a8d278e4520a22a32d19f03a7b75f Mon Sep 17 00:00:00 2001
From: Andrew Thornton <art27@cantab.net>
Date: Thu, 20 Aug 2020 17:50:35 +0100
Subject: [PATCH] Prevent NPE on commenting on lines with invalidated comments
Only check for a review if we are replying to a previous review.
Prevent the NPE in #12239 by assuming that a comment without a Review is
non-pending.
Fix #12239
Signed-off-by: Andrew Thornton <art27@cantab.net>
---
services/pull/review.go | 2 +-
templates/repo/diff/box.tmpl | 5 ++++-
templates/repo/diff/section_unified.tmpl | 5 ++++-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/services/pull/review.go b/services/pull/review.go
index 25e0ca858..5a77a4da1 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -29,7 +29,7 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models
// - Comments that are part of a review
// - Comments that reply to an existing review
- if !isReview {
+ if !isReview && replyReviewID != 0 {
// It's not part of a review; maybe a reply to a review comment or a single comment.
// Check if there are reviews for that line already; if there are, this is a reply
if existsReview, err = models.ReviewExists(issue, treePath, line); err != nil {
diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl
index 7338c1ee6..397356fe6 100644
--- a/templates/repo/diff/box.tmpl
+++ b/templates/repo/diff/box.tmpl
@@ -155,7 +155,10 @@
{{if gt (len $line.Comments) 0}}
{{$resolved := (index $line.Comments 0).IsResolved}}
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
- {{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
+ {{$isNotPending := false}}
+ {{if (index $line.Comments 0).Review}}
+ {{$isNotPending = (not (eq (index $line.Comments 0).Review.Type 0))}}
+ {{end}}
<tr class="add-code-comment">
<td class="lines-num"></td>
<td class="lines-type-marker"></td>
diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl
index 5f87a4176..2508c01fe 100644
--- a/templates/repo/diff/section_unified.tmpl
+++ b/templates/repo/diff/section_unified.tmpl
@@ -35,7 +35,10 @@
{{if gt (len $line.Comments) 0}}
{{$resolved := (index $line.Comments 0).IsResolved}}
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
- {{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
+ {{$isNotPending := false}}
+ {{if (index $line.Comments 0).Review}}
+ {{$isNotPending = (not (eq (index $line.Comments 0).Review.Type 0))}}
+ {{end}}
<tr>
<td colspan="2" class="lines-num"></td>
<td class="add-comment-left add-comment-right" colspan="2">
--
2.25.1 |
Only check for a review if we are replying to a previous review. Prevent the NPE in go-gitea#12239 by assuming that a comment without a Review is non-pending. Fix go-gitea#12239 Signed-off-by: Andrew Thornton <art27@cantab.net>
Only check for a review if we are replying to a previous review. Prevent the NPE in go-gitea#12239 by assuming that a comment without a Review is non-pending. Fix go-gitea#12239 Signed-off-by: Andrew Thornton <art27@cantab.net>
…#12550) * Prevent NPE on commenting on lines with invalidated comments Only check for a review if we are replying to a previous review. Prevent the NPE in #12239 by assuming that a comment without a Review is non-pending. Fix #12239 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add hack around to show the broken comments Signed-off-by: Andrew Thornton <art27@cantab.net>
…gration) (#12549) * Prevent NPE on commenting on lines with invalidated comments Only check for a review if we are replying to a previous review. Prevent the NPE in #12239 by assuming that a comment without a Review is non-pending. Fix #12239 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add hack around to show the broken comments Signed-off-by: Andrew Thornton <art27@cantab.net> * Add migration and remove template hacks Signed-off-by: Andrew Thornton <art27@cantab.net>
Apologies that this took so long to fix. |
[x]
):Description
We are using Gitea on a small team (5 programmers) and fairly regularly run into a case where the "Files Changed" tab on a pull request is no longer accessible with some variation on this error message:
1.12.2:
1.12.1:
We have sometimes been able to find the offending comment in the database and update its Review ID to the appropriate ID. This gets difficult when a lot of comments have been made on other PRs between noticing the problem and trying to fix it.
We don't have a specific reproduction case that triggers this, but in general it seems it is sometimes possible to fail to assign the appropriate review ID in a comment which then breaks the ability to review changes line-by-line on a given PR.
Screenshots
Nothing to show, really, since it's just an error. Loading the Files Changed tab attempts to GET /org/repo/pulls/:pull_id/files, which returns 500 and the above error as plain text.
The text was updated successfully, but these errors were encountered: